An Overview of The MEF Framework
"MEF (Managed Extensibility Framework) is an awesome framework that allows easily loading types at runtime making your apps plugin-ready. Using reflection magic, MEF makes it super easy for any app to accept plugins.
Following are 5 easy steps involved in making your app plugin-ready using MEF:
- Define an interface for plugins. This is the interface that each plugin must implement.
- Define a metadata interface. This interface tells your app out of so many plugins which one is the correct plugin for a given piece of functionality.
- Define one or more concrete plugin classes.
- Decorate each class with some attributes.
- In your app write a few lines of code to invoke MEF, and let the magic happen.
While it may not be very useful in the real world, let’s say that we have an extensible app that can write provided text to Console using different styles. For example input string of “style=warning|This is a warning!” will reproduce text “This is a warning” with red background and white foreground colors. Since our app is extensible we can create new style plugins at any time, place them in appropriate folder, and start using new styles without ever having to recompile our main app.
I know everyone reading my blog already knows about MEF, right? And instead of building your own plugin, app extension, etc. frameworks, you've long moved to MEF? That you've seen just how awesome MEF is by how it's used in Visual Studio 2010? Well then this post isn't for you...
This post is for those new to my blog, those that might not know about MEF like you do. Those that might have heard of MEF, but haven't yet had a chance to check it out. For those who are looking for a quick, just-in-time, info-dump on how to get started using it, to start using it today. This post is for you...
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)