.NET Zone is brought to you in partnership with:

I’ve been a Windows developer since 3.0 and caught the Visual Basic wave early with v1. I’ve released a “production” application in every version of VB since then (except VB for DOS). Focusing on enterprise, line-of-business development I’ve built Call Center Applications, Mortgage finance systems, Customer Relationship Management tools and more recently I’ve been in the Litigation Support/Electronic Data Discovery/Electronically Stored Information space. Greg is a DZone MVB and is not an employee of DZone and has posted 271 posts at DZone. You can read more from them at their website. View Full User Profile

An Overview of The MEF Framework

04.22.2012
| 2441 views |
  • submit to reddit

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

Published at DZone with permission of Greg Duncan, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)