MEF is an acronym for Managed extensibility framework. This is a library from Microsoft to build extensible applications. It is attributed programming model as it works on attributes like import, importmany, export, importingconstructor, exportfactory, etc. MEF is very helpful for larger applications where injecting the dependencies in between the distant parts is usually quite complex. It only requires copying the dll in the bin folder of the existing application.
MEF is not an IoC (Inversion of control) container, even though it uses IoC concepts. MEF focuses on application extensibility with component discovery and composition. IoC containers are most useful with static dependencies whereas MEF can work with dynamic dependencies. MEF is great at the plug-in pattern for a whole assembly at ‘run-time’, while something like Unity make the code easier to change at design-time.
Client Challenge
The client needed to expand the functionality and look & feel of their resource and project management application. The existing application could not deliver satisfying results and was not compliant with Service Legal Agreements (SLAs) as demanded by their enterprise customers. In addition, the existing architecture was not that much flexible to support additional functionality, data presentation or customization.
Extending the application via MEF:
Integrating the existing application with Microsoft MEF benefited with:
Technology
Part: A Part is an object (e.g. a class, a method or a property) that can be imported or exported to the application.
Import Attribute: It defines the need that a part has. It applies in a scenario when we require only a single attribute.
Export Attribute: Export attribute fulfills the needs which are created by import attributes. We can import only those parts which are decorated with export attribute.
ImportMany Attribute: This attributes allows us to consume multiple parts which are decorated with export attributes.
Contract: The import and exported parts need to talk between themselves via some contract. So they are the bridge between import and export. (e.g. an Interface or predefined data type like string)
Catalog: An object that helps in discovering the available compose-ready parts from an assembly or a directory.
Compose: In MEF jargon, Compose is that area where the Exported parts will be assembled with the imported ones.
Glossary:
[1] Ten Reasons to use the Managed Extensibility Framework by Jeremy Likeness – Article Source
[2] Migrate from Basic to MVVM and MEF Composable Patterns for a Silverlight Application – Part 1 by Shenwei Liu – Article Source