Session – Building Extensible Rich Internet Applications with the Managed Extensibility Framework

November 19, 2009


In this great session, Glenn Block and my collegue Ariel Ben Horesh have talked about Managed Extensibility Framework for Silverlight 4 for building customizable applications that can easily be extended by third parties. Whether you are building an extensible data grid, a custom rules engine, a pluggable editor, or a composite application such as a pluggable CRM system, you want to learn about MEF. They explained how to use MEF to decouple applications into more maintainable the application into dynamically deployable chunks that download on-demand.

The managed extensibility framework (MEF) is a new library in .NET 4.0 and Silverlight 4 for building applications that can be extensible.

MEF takes parts and tier them together, like LEGO, based on the configuration of the user. The concept is that your application is built up from parts.

The basics, core concept to work with MEF are:

Export it

You can create a part and export it so it could be discovered and import to compose the application.

Import it

I need something, so you can import single or many parts.

Compose it

Now that you’ve got all of the parts, compose them together to compose an application.

For example, you have a dash board built of widgets. You can create widgets and export them. Just decorate the widget with the Export attribute. The widget itself can Import other parts. The dash board now can import one or many exports. In the Silverlight main page you should call PartInitializers.SatisfyImports() to satisfy all imports. This is it. Now MEF will automatically load and compose all parts.


Provides meta information for exports, for example where the widget should be located by default, on the top are at the bottom.

To define metadata you should define types an and interface which defines the metadata, then export it using ExportMetadata and acquire it while import. While import you should work with the Lazy<P, M> instead of directly importing the par

Custom Attributes

In MEF, instead of using the out-of-the-box attributes (Import, Export) you can create your own. For example WidgetAttribute. In such case you should create an attribute and derive it from the MEF ExportAttribute.


In MEF there is an option for re-composition, meaning that MEF can be notified while new parts are added at run time. To turn this on you should set the Import.AllowRecomposition to true. Now if you download packages at runtime, MEF will be notified and compose the new parts.

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



  1. TomNovember 19, 2009 ב 22:37

    Still the question is MEF or Prism?

    For UI composition i will choose Prism

  2. Tomer ShamamNovember 22, 2009 ב 14:57

    Hi Tom,

    MEF and Prism target different scenarios.
    I would also use Prism for WPF UI composition but will use MEF for other scenarios in the same application, , hopping that the next Prism version will integrate MEF.