Note – these posts are put together after a short time with Silverlight 4 as a way of providing pointers to some of the new features that Silverlight 4 has to offer. I’m posting these from the PDC as Silverlight 4 is announced for the first time so please bear that in mind when working through these posts.
The Managed Extensibility Framework (MEF) has been getting a lot of interest lately and it’s something that’s out on CodePlex and it’s also part of .NET Framework 4.0.
It’s also part of Silverlight 4.
The name’s a good one – it’s a framework for building an application that is made up of a bunch of loosely coupled components with a lot of flexibility around component discovery, registration, lookup and lifetime management. If I had to sum it up in my own words I’d say something like;
MEF composes an application by extensibly discovering a set of components which offer exported functionality and ( possibly ) rely on imported functionality. The link between the two is a simple string name ( a MEF “contract name” ) which is usually represented by a .NET type name and MEF has the capability to plug things together where it finds ( possibly further constrained ) matches.
There’s some overlap with Unity and some of the modularity pieces from PRISM in terms of what the framework can do for you but I’d say that it generally feels simpler and it’s more skewed towards discovery – there’s a good discussion on the pros/cons of viewing MEF as a general purpose Inversion-of-Control container ( like Unity ) which is well worth a read.
The MEF types exist in System.ComponentModel.Composition.dll and System.ComponentModel.Composition.Initialization.dll and live in a handful of namespaces within there.
I was pondering whether to turn this post into a “So, what’s MEF?” style post but I decided that, for now, it’s enough to say that MEF is in the beta bits for Silverlight 4 and to revisit MEF in a subsequent post. In the meantime, MEF has a bunch of “Guide Docs” which are very a bit like a recipe to follow in order to use MEF and then there’s the architecture docs which provide more of a view as to what the moving parts are and then this hosting doc which I found perhaps the most helpful for getting a bit more detail.