The Managed Extensibility Framework
The Managed Extensibility Framework is "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."
(I was too lazy to think about my own description for it, so I just copied the official one.)
Probably the first thing that you should know about MEF is what will undoubtedly be the most common cause for confusion.
The Managed Extensibility Framework is not an IoC container.
This is not a slug at MEF, it is an important distinction. If you try to judge MEF through IoC container glasses, you will come away confused. It may walk like a duck, but it meows.
MEF is, first and foremost, a composition framework. And its target audience are BIG applications. Those two, taken together, are important to understand what MEF is and how we should look at it.
What is the difference between a composition framework and an IoC container? On the surface, they are doing much of the same thing, managing dependencies for the application in an automated fashion. The difference (and the devil) are in the details.
IoC containers have long ago stopped just managing dependencies. They are taking care of a lot of additional responsibilities. Managing lifecycles, proxies, aspect orientation, event aggregation, transaction semantics and a lot of other features.
In addition to that, there is a lot of focus on problem solving by utilizing the container. Things like generic specialization or component selectors allows you to approach a lot of very complex problems in a completely different mindset.
A composition framework, on the other hand, is focused on a single goal: dependency management.
It sounds like MEF is a subset of what an IoC container is doing, I know. This is not the case. MEF, the bits we have right now, are doing a lot more in the area of dependency management than the containers are doing. Where a container is usually static and opaque, MEF primary focus is to make the dependency management itself a dynamic and transparent process.
This is where the second part of the MEF design goals come into place. MEF is targeting Big applications. The really big ones. One of the immediate customers of MEF is Visual Studio itself.
Things like ( take a deep breath ):
- being able to query meta data without loading assemblies
- statically verify the dependency graph for all the components and reject those that would put the system in in valid state
- being explicit by default
- contract adapters
- metadata tagging
All of those are key concepts in the overall dependency management theme. And all of those are the product of having a Visual Studio being one of the first consumers of this project. Visual Studio needs this kind of things, across tens of thousands of components. And MEF is setup to handle those kind of scenarios.
So, MEF is very similar to IoC containers, but it has very different goals (or maybe it would be more accurate to say that it has very different priorities).
Another important aspect of MEF has nothing to do with it at all and everything to do with where it is going to be used. MEF is going to ship with .Net 4.0, which put it in a position to be very widely distributed, but more importantly, since it is on the framework, it can be used by other parts of the framework. Which is where it get interesting.
There are a lot of places in the framework that could make use of a container. IControllerFactory is a good example of something that should not exists, for example. I am ambivalent with regards to that, because I think that the correct abstraction for those kind of things is not necessarily MEF, but that is beside the point.
And that is enough for now, I am going to toss a coin and see if it is going to be Erlang code or meta documentation next.
So, let me guess, you searched your stock photo source for 'cat AND duck'?
And the stock photo source was 'Google'?
LOL, this one fits better with your description.
This is the first place I've seen a useful description of the MEF. So, Oren, I'm here to tell you that some of us ALSO read the words in your posts, not just look at the pictures :)
An interesting possibility of MEF is being able to dynamically re-compose a graph of components after one or more were added / removed from the system at runtime. Not sure if any IoC container can do that currently, although I guess they could be modified to handle such a scenario.
Wow, Oren, you've given the most eloquent description of what we are to date. Are you trying to join the MEF team or something? :)
http://tirania.org/blog/archive/2008/Sep-07.html (right off the comment on CodePlex). I think they are still duking out the license but that doesn't look too hopeful.