Wednesday, February 29, 2012

Understanding Managed Extensibility Framework

Managed Extensibility Framework (MEF) is a new library which was introduced with .NET framework 4.0 for creating lightweight, extensible applications. What we can do with MEF is really amazing and it really just surprised me. So thought to write a post about MEF, because I am pretty sure it's going to be one of the nicest concepts introduced by Microsoft.

When we are developing an application, if we thought about the cost and the time, mainly it will be 20% for the original software development and the rest 80% will be for the software maintenance. The thing is later we will have to add new modules to original application which means we will have to extend the original application. When extending an application, as developers we know basically two things. That is KNOWN part and UNKNOWN part. The known part is since we know how we developed the application, we have the ability to change the source code. The unknown part is, if we want to plug our application with a third party application, we know nothing about their implementation. Because when we are developing, it wasn't a requirement.

So the best practice is to compose an application from various of pieces. As one of the principles in Object Oriented Design says, which is Open/Closed Principle, software entities should be open for extension but closed for modification. That is we should be able to extend the behavior of classes etc without modifying the source code. Classes' should have one reason to change. That is if one of the dependencies change like recently introduced bug etc.

Managed Extensibility Framework

Managed Extensibility Framework is designed to help developers to extend the application without changing the original source code. The core concept behind MEF is, MEF is aiming on composing an application which is dynamically compiled rather than statically compiled. To bring all these nice features MEF stands upon few concepts.
  1. Parts
    • An application is built of Parts. This is the core of MEF. You can think of it like building blocks of MEF.
  2. Export
    • Once you have implemented a Part, you can Export it. By exporting you are declaring "This part is available for the rest of the system. If you want it, you can consume it.".
  3. Import
    • Now think of another Part.  He is saying "I want this part for me to be perfect. I want to consume it.". When he is using your part, that is importing.
  4. Compose
    • To satisfy their needs we take all the Exports, we take all the Imports, we match them with each other and we are putting them with each other. How MEF really does is, in MEF there is a concept called Catalogs. Catalogs discovered the Parts and provide the Parts. And finally we have the Container which is a match maker. It is responsible for matching all the Exports with Imports.

For more information on MEF visit MSDN,

Hope you all got some basic understanding in Managed Extensibility Framework. Please feel free to post your valuable feedback.

Happy Coding.


No comments:

Post a Comment