Saturday, April 21, 2012

MEF Review OR If you're building your own custom plug-in frameworks and not using MEF, you might be a ...

Software Rockstar - MEF: Easily Creating Plug-in Based Apps In .NET

"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:

  1. Define an interface for plugins. This is the interface that each plugin must implement.
  2. 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.
  3. Define one or more concrete plugin classes.
  4. Decorate each class with some attributes.
  5. 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.

...

image..."

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...

1 comment:

Anonymous said...

For anyone who is looking to use MEF within Windows 8 Metro-style apps I have just posted about this at http://andyonwpf.blogspot.co.uk/2012/04/using-mef-in-metro-style-applications.html.