Managed Extensibility Framework (MEF)

One of the many announcements made at the PDC was that Visual Studio 10 will be built on top of WPF. In addition, VS will be using MEF as an extensibility mechanism. I just wanted to take a few minutes to explain what MEF is all about.

The Managed Extensibility Framework (MEF) is a library that makes it easy to develop reusable components. The framework provides a standard way for a host application to discover, expose and consume component extensions without the need for each of them to be coupled together.

At the heart of MEF is a ComposablePart, which exposes services or consumes externally provided services. This is done using a Contract, which can be as simple as adding an Import (to consume) or Export (to expose) attribute.

Although MEF is still in development, it already provides a number of key benefits, and would be worth a look if you are, or plan on working on extensible applications. Full source and documentation can be found on CodePlex. It also includes samples, but if there’s interest I’ll add a sample on my blog as a step-by-step walk through.

Comments (2)

  1. Kris says:

    What is the difference b/w Unity DI framework and MEF? Where would one use one over the other?


  2. Hi Kris-

    The difference is primarily in the more detailed goals each one tries to achieve. Although there is some overlap, you could technically use both, as opposed to one over the other.

    The Unity framework is primarily focused around dependency injection, and giving you some flexibility around how and what is getting injected (i.e. constructor, property, and method call injection).

    MEF is specifically targetted towards extending applications, and does not provide all the features of the Unity Container. You currently have to use attributes to define what you will expose or consume (Import/Export), but the advantage is that it’s very simple to use.

    There is a related mail thread on the MEF Discussion group that also explains the relationship with Add-Ins:

    And apologies for the delay; I passed your question along to the MEF team, but have yet to receive a response. I hope my answer helps clarify!

Skip to main content