Tuesday, June 30, 2009

MEFify an Applications


What is your favorite program? Office, Visual Studio, Photoshop, World of Warcraft, Reflector?

What do they have in common? 99% of the most popular software available today is extendable in some way, shape or form. Surely you do not have to be extensible to be popular?

Is the software that you are currently writing extensible? If not, why not?

Extensibility in the past has been extremely hard, you had to do all the work yourself using reflection! Not impossible but in time you will learn that security, isolation, crossing application boundaries & lifetime management is extremely difficult to do yourself! Microsoft also released System.AddIn (Managed AddIn Framework). MAF did make it a little easier once you got your head round the pipeline… but still too difficult to easily add to your application…


Introducing Microsoft Extensibility Framework

The Managed Extensibility Framework (MEF) is a new library in .NET that enables greater reuse of applications and components. Using MEF, .NET applications can make the shift from being statically compiled to dynamically composed. If you are building extensible applications, extensible frameworks and application extensions, then MEF is for you.

Let's Get Started

I created a pretty simple clone of Window Live Writer. Live Writer has LOADS of plugins available. Each plugin should be capable of adding content to the document.



Composable Parts do not directly depend on one another, instead they depend on a contract, which is a string identifier. Every export has a contract, and every import declares the contract it needs. The container uses the contract information to match up imports to exports. If no contract is specified, MEF will implicitly use the fully qualified name of the type as the contract. If a type is passed, it will also use the fully qualified name.

See full detail: http://www.codeproject.com/KB/cs/MEFIntro.aspx

No comments: