The Managed Extensibility Framework (MEF) is a composition layer for .NET that improves the flexibility, maintainability and testability of large applications. MEF can be used for third-party plugin extensibility, or it can bring the benefits of a loosely-coupled plugin-like architecture to regular applications (MEF support a Plugin Model).
There are two versions of MEF:
System.ComponentModel.Composition.* which has shipped with .NET 4.0 and higher and Silverlight 4. This provides the standard extension model that has been used in Visual Studio.
System.Compostion.* is a lightweight version of MEF, which has been optimized for static composition scenarios and provides faster compositions. It is also the only version of MEF that is as a portable class library and can be used on phone, store, desktop and web applications.
2. MEF model
Roughly speaking, MEF's core is comprised of a catalog and a CompositionContainer?. A catalog is responsible for discovering extensions and the container coordinates creation and satisfies dependencies.
- Parts (i.e. Component) are the cornerstone of MEF. A composable Part offers up one or more Exports, and may also depend on one or more externally provided services or Imports. It is throught this relationship between what a part needs, and what a part can provide that the composition takes place. Service definition is done via Contracts (e.g. an Interface or predefined data type like string).
- Containers perform the actual composition between parts by matching Exports with Imports, that is, service providers with service consumers.
- Catalogs (i.e. Component Repository) are in charge of part discovery. Using different built-in catalogs, an application can find parts within a given assembly or a given folder at runtime. Containers use catalogs to find out which parts they can use during composition.
Longer description here
3. MEF Examples
4. MEF Architecture
MEF as seen on Fig. below, is divided into three main layers Container, Primitives and Attributed Programing Model.
Each of these parts is described in Full MEF Architecture here.
Fig: Different layers in the Managed Extensions Framework.
5. More about MEF
Are you interested to know more about MEF (e.g. "MEF vs standard IoC Container", "MEF Visualizer", "Why to use MEF", "More learing materials" etc.) click here .
Parking lot example writen in C# without using MEF ParkovistePlain. Implementation Attach:ParkingLot_Plain.zip
Parking lot example writen in C# using MEF Dependency Injection ParkovisteMEF. Implementation Attach:ParkingLot_MEF.zip