# Saturday, 30 May 2009
 #
 

Microsoft Managed Extensibility Framework (MEF) is a framework for building extensible applications. Using MEF, you can build extensible applications constructed of loosely-coupled composable parts.  By constructing an application of parts, any part can be replaced at runtime, without recompiling or redeploying the entire application. 

One use would be to create an extensible application with a plug-in architecture, allowing users to extend it or to replace parts of it, without recompiling.  As such, you would not need to release the source code along with your application. 

Microsoft already has several technologies to accomplish similar things.  Visual Studio 2008 and Microsoft Office 2007 each has a plug-in framework that allows users to extend the application.  MEF promises a single extensibility framework that can be used across all Microsoft applications.  This frees developers from the need to learn a different framework to extend each application.  In fact, the editor in the upcoming Visual Studio 2010 (now in beta) is built on top of MEF, so that developers can use MEF to add plug-ins to the IDE.

Of course, there are simpler technologies built into the .Net framework that allow you to extend applications at runtime. 

In the current version of .Net, we can code to interfaces, instead of concrete classes.  Doing so gives us the ability to defer to runtime which class to instantiate.  Our code is flexible enough to accept any class, as long as that class implements the expected interface.  However, we must decide at compile time all possible classes that might be instantiated at runtime.  This is because, in most cases, we cannot instantiate a class without setting a reference to the assembly in which that class resides.  And setting references is something done prior to compiling.  Using MEF, we can instantiate classes even if there is no explicit reference set.  MEF takes care of that for us.

Managed Extensibility Framework promises to solve the problem of building loosely-coupled, extensible applications without forcing developers to learn a new skill set for each application.  It does so without the disadvantages of forcing a recompile and loading classes into memory unnecessarily when an application is extended at runtime.

Note: As of this writing, MEF is in Community Technology 5 and is planned to be released as part of .Net 4.0

.Net | MEF