The recently announced managed extensibility framework (MEF) of .NET 4.0 - is it a dependency injection framework? Will Microsoft Unity from Patterns and Practices be obsolete in 4.0 ? How does MEF compare to a framework like Unity?
When boiled down, the main difference is that IoC containers are generally most useful with static dependencies (known at compile-time), and MEF is generally most useful with dynamic dependencies (known only at run-time). As such, they are both composition engines, but the emphasis is very different for each pattern.
The Managed Extensibility Framework or MEF is a library for creating lightweight, and extensible applications. It allows application developers to discover and use extensions with no configuration required. It also lets extension developers easily encapsulate code and avoid fragile hard dependencies.
For those who don't know, the Managed Extensibility Framework (MEF) is alive and well, and has been ported to . NET Core as System.
The MEF is a . NET library that lets you add and modify features of an application or component that follows the MEF programming model. The Visual Studio editor can both provide and consume MEF component parts. The MEF is contained in the . NET Framework version 4 System.
Specifically addressed in the PDC 2008 2nd Keynote by Scott Guthrie, MEF has a lot more to do with things like extending Visual Studio 2008 and other applications, without having to use all the COM and older technologies... A very good demonstration of extending the text edition in VS2008 was shown among other things. Start about an hour and 15 minutes into the 2nd day keynote (http://www.microsoftpdc.com) and you'll get direct information, but basically if you are going to "build an application with built in extensiblity points that can easily be discovered, and which supports discovery of extensions," then MEF is what you want. UNITY is what you want for a high-quality IoC container that does DI as well as the other solutions out there but has great and easy integration with the Enterprise Library.
Regarding Unity in the EL4.0 (now 4.1 -- http://msdn.microsoft.com/en-us/library/dd203099.aspx) its actually a IoC that sits on top of the version 2 ObjectBuilder and the EL4.1 has extensibility points for unifying the configuration of various EL application blocks with Unity.
MEF vs. Unity is like comparing apples to oranges. Some great and specific podcast/webcast(s) that describe UNITY in full are here, which I highly recommend:
DotNetRocks Show #393 http://www.dotnetrocks.com/default.aspx?showNum=393 DNR.tv Show #126 http://www.dnrtv.com/default.aspx?showNum=126
I saw one write up that made it sound like one but more information (Scott Guthrie at PDC2008[Video/wmv]) made me think it's more than a dependency injection framework. From the sounds of things it can be used for dependency injection but also does more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With