Search code examples
unity-containerprismmef

New Prism Project - Use MEF or Unity?


I'm starting a new personal Prism 4 project. The Reference Implementation currently uses Unity.

I'd like to know if I should use MEF instead, or just keep to Unity.

I know a few discussions have mentioned that these two are different, and they do overlap, but will I be missing out if I simply choose Unity all the way?


Solution

  • Also check out the documentation:

    Key Decision: Choosing a Dependency Injection Container

    The Prism Library provides two options for dependency injection containers: Unity or MEF. Prism is extensible, thereby allowing other containers to be used instead with a little bit of work. Both Unity and MEF provide the same basic functionality for dependency injection, even though they work very differently.

    Some of the capabilities provided by both containers include the following:

    • They both register types with the container.
    • They both register instances with the container.
    • They both imperatively create instances of registered types.
    • They both inject instances of registered types into constructors.
    • They both inject instances of registered types into properties.
    • They both have declarative attributes for marking types and dependencies that need to be managed.
    • They both resolve dependencies in an object graph.

    Unity provides several capabilities that MEF does not:

    • It resolves concrete types without registration.
    • It resolves open generics.
    • It uses interception to capture calls to objects and add additional functionality to the target object.

    MEF provides several capabilities that Unity does not:

    • It discovers assemblies in a directory.
    • It uses XAP file download and assembly discovery.
    • It recomposes properties and collections as new types are discovered.
    • It automatically exports derived types.
    • It is deployed with the .NET Framework.