MEF (Managed Extensibility Framework)

MEF is a new framework for creating customizable applications that can be used by any .NETcompatiblevlanguage. Glenn Block (PM for the new Managed Extensibility Framework in .NET 4.0) says:vQuite simply, MEF makes building extensible apps, libraries and frameworks easy. It shares some common characteristics of other frameworks out there, but it also addresses a whole new set of problems that arise in building extremely large scalable extensible systems.

Let’s say you have created a Tetris application and want to allow users to extend it by creating their own shapes of bricks. MEF enables you to do this by defining a brick interface and then dynamically loading and resolving the created extensions.

When creating a MEF application, take the following steps:
1. Define areas of the application that can be extended and decorate them with the [Import] attribute.

2. Determine a contract/interface that defines what your extensions must do/be (this could be a simple as they must of String).

3. Create an extension that meets these requirements and decorate it with the [Export] attribute.

4. Modify your application to load these extensions.

Why Use MEF?
Using MEF has the following advantages:
• Microsoft hopes that MEF will become the preferred standard method of creating extensions. By utilizing a standard plug-in model, your extensions could be used in many applications

• MEF provides a number of flexible ways to load your extensions.

• Extensions can contain metadata to provide further information about their capabilities. For example, you may only want to load extensions that can communicate securely.

• MEF is open source and works on VS2008 (

MEF Catalogs
MEF uses a concept called catalogs to contain extensions. Catalogs come in three different flavors:
• Assembly (extensions are contained in a .net assembly)
• Directory (extensions are in a physical directory)
• Aggregate (a catalog type that contains both assembly and directory extensions)

An important feature of MEF is that you can provide additional information about an extension's capabilities with metadata. MEF can then utilize this information to determine the most appropriate extension to load and query its capabilities. For example in the previous logging example you might specify whether the logging method is secure or not and then in high security environments only load extensions that communicated securely. Meta data can be defined at a class or method level.

Source of Information : Apress Introducing dot NET 4.0 with Visual Studio 2010


Subscribe to Developer Techno ?
Enter your email address:

Delivered by FeedBurner