Terminology

Let's start by explaining the terminology that we will use throughout this chapter.

  • Parts: Parts are components of your application that MEF can compose together. For example, say that you have a shell application that hosts modules, where the shell application and the modules are loosely coupled, with MEF providing the modules to the shell application at runtime. In this scenario, both the shell application and the modules can be considered parts. Parts are the classes that provide services to other parts, which we'll refer to as exports, and/or consume services from other parts, which we'll refer to as imports. In doing so, they enable MEF to discover them and compose them together.
  • Exports and imports: A part provides services to other parts by exporting them. A service may be the part itself (the class), its properties, and/or its methods. By doing so, it makes itself known to MEF, enabling other parts to consume those services. These parts consume those exports by importing them, with MEF composing them together. In this chapter, we'll reference exported services as exports, and imported services as imports.

images Note Parts can export their properties and methods but are often exported themselves (i.e., the class representing the part is itself exported). This chapter will focus only on exporting classes, and because a part is a class, you'll therefore see references to exporting/importing parts throughout this chapter, rather than the more correct, but somewhat vague, term “services.”

  • Contract: A contract is used to identify an export so that it can be found and used by an import, with the contract essentially acting as a bridge between the two. As a result of using a contract to bridge the exports and the imports, the parts will be loosely coupled. Exports declare a contract. When MEF encounters an import, it searches for an export with a matching contract. This contract may be the class's type, an interface that it implements, or simply a string used to name the contract. When a corresponding export is found, it will instantiate the part, if MEF does not already have a reference to an instance of the part, and “inject” it where it is needed.
  • Catalog: A catalog is responsible for discovering parts and providing them to the composition container.
  • Composition container: The composition container composes parts together. The parts are obtained from the catalog that the composition container is configured to use. When the composition container encounters a part containing an import request, it will look for a corresponding export with a matching contract to inject into the part.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset