Using Unity or MEF for DI? Mef is needed to load modules ?

Topics: Prism v4 - Silverlight 4, Prism v4 - WPF 4
Jan 7, 2011 at 8:58 AM

Hi there,


I have been using Unity for a while now in ASP.NET MVC and it appears here in PRISM v4 it can also be used but i am confused about weather i should use MEF or UNITY for the DI? My new project with Prism v4 is with silverlight.


It appears that MEF and Unity both do DI - am i correct here?


If i am not mistaken then MEF is used to also load MODULES on demand like plugins.


I suppose my problem here is do i continue to use UNITY or should i change over to MEF for the DI considering that MEF is needed for modular loading.


Unity seems to have good documentation but MEF i can't seem to find good documentation. I would appreciate any feedback.


Is Prism working towards combining MEF and unity, is it going to drop support for 1 over the other?


Any help or information reallly appreciated

Jan 7, 2011 at 2:36 PM
Edited Jan 7, 2011 at 2:36 PM

Yes they both do DI.

Both will load modules equally the same

If you are more familiar using Unity stick with what you know.

MEF has docs at

As far as I have seen, no they are keeping them separate implementations.

Jan 7, 2011 at 2:47 PM


As explained in this chapter from the Prism MSDN documentation, Prism is container agnostic, so you can leverage either MEF or Unity or any other Dependency Injection mechanism for your application. From the documentation, "Dependency injection containers, often referred to as just "containers," are used to satisfy dependencies between components; satisfying these dependencies typically involves registration and resolution. The Prism Library provides support for the Unity container and for MEF, but it is not container-specific"

The choice for which container to use depends on your preference. You can download and load modules on demand using Unity, as well as MEF. For example, there is a MefXapModuleTypeLoader class and a XapModuleTypeLoader class available in the Prism Library, which handle remote module downloading for MEF and other containers, respectively. You can read more about this in the Modularity chapter of the Prism MSDN documentation.

As for the MEF documentation, you might find the following resources useful:

I hope you find this helpful.

Guido Leandro Maliandi