Managed Extensibility Framework is a framework which mostly used to write the reusable plugins. It provides a composition layer to develop a large system in to many smaller reusable, maintainable, traceable and flexible plugins. It brings the benefits of a loosely-coupled plugin-like architecture to applications.

It comes with .net 4.0 and 2nd version is still in under development.

Why Managed Extensibility Framework come in to world?

Imagine you have to develop an integrated system of sculpture which does the following task?

  1. Make the idol with raw material
  2. Paint the idol with colors.
  3. Wrap the idol in boxes.
  4. Move the boxes in Store.

Now there is situation when in these 4 tasks few subsets can be performed as well. Like

  • Scenario 1 :If you need without any color idol should be reached to store: so followed only 1, 3, 4th step and left 2nd one.
  • Scenario 2 : You need not to send the idol to store : you followed only 1,2 3

So typically how we develop this system?

You develop 4 plugins which does these 4 tasksand each plugins have information about their next plugins and you call these plugins from one plugins to another plugin. It makes dependentsystem and most of the time these plugins are specific to that particular system and can’t be reusable as each plugins must know about configuration of their next plugins and once if one failed next task must be fail.
What is MEF way to do it?

Develop 4 plugins which provide a way to discover them implicitly, via composition. A MEF component, called a part, declaratively specifies both its dependencies (known as imports) and what capabilities (known as exports) it makes available. When a part is created, the MEF composition engine satisfies its imports with what is available from other parts. MEF allows applications to discover and examine parts by their metadata, without instantiating them or even loading their assemblies.

So now plugins don’t need to know about others, they are discoverable at runtime MEF allows applications to discover and examine parts by their metadata, without instantiating them or even loading their assemblies. As a result, there is no need to carefully specify when and how extensions should be loaded.

So now since every plugins are available dynamically its quite flexible to load or unload usable plugins.

For example for scenario 1: only 1, 3 and 4th plugins will be loaded dynamically And since these are totally independent to each other can be reused in other system across the applications.

Boost Factor to use Managed Extensibility Framework:

  1. Dependency injection and inversion of control.
  2. ImportMany
  3. Modularity.
  4. Customization
  5. Extensibility

Core Features of Managed Extensibility Framework:

  • CompositionContainer : It contains all the parts available and performs composition.
  • Catalog : It is an object that makes available parts discovered from some source. MEF provides catalogs to discover parts from a provided type, an assembly, or a directory.
  • Imports and Exports attributes: Imports and Exports should match through a contract.
  • ImportMany :An ordinary Import attribute is filled by one and only one Export. If more than one is available, the composition engine produces an error. To create an import that can be filled by any number of exports, you can use the ImportMany attribute.

Typical Managed Extensibility Framework Application: I Tried to explain with pseudo code that help you to understand the workflow otherwise a sample project (only for taskContract and composition helper) is available. Rest plugins are separate project which need to do their specific functionality which you can write as usual you do in other application

Vidya Sagar
Software Engineer
Delhi, India