Difference between MEF and IoC containers (like Unity, Autofac, SMap, Ninject, Windsor.Spring.net, etc.)

Yogesh picture Yogesh · Mar 22, 2013 · Viewed 17.6k times · Source

I have been searching about the dependency injection and read a few articles. But still I am unable to find out the difference between MEF and other IoC's. So, my question is this: In which situation should I prefer to use a MEF or IoC container?

Why is it good to use MEF with PRISM for (WPF & Silverlight) or for desktop applications?

Whereas in web application people use IoC containers.

So, what is the criteria to decide which dependency technique I should use?

I have been through the article http://devlicio.us/blogs/casey/archive/2009/12/18/what-is-the-difference-between-an-ioc-container-and-mef.aspx , but I could not determine anything.

Answer

Yogesh picture Yogesh · Mar 25, 2013

Eventually what I have concluded about the MEF vs IoC container is as follows:

MEF is preferred to be used when one has to deal with unknown types or a plugin based architecture.

IoC containers are preferred to be used with known types.

Moreover, MEF is an architectural solution for dependency injection

Whereas, IoC containers are code-level solutions for dependency injection.

IoC containers are just dependency injection techniques which populates the instance of a class and if the constructor of those classes requires objects of other classes, then IoC also injects the required objects. But MEF does more than just dependency injection. Although, MEF also uses an IoC-based approach for dependency injection, but MEF does so many other things apart from dependency injection.

MEF has got two components:

  1. Catalog: Is responsible for discovering extension

  2. Container: Provides the ability to load an extension to a running application

MEF is more than just dependency injection techniques. It is used wherein we need a plugin-based architecture for our application, but at the same time MEF uses an IoC-based approach for dependency injection.

I am expecting more people to comment on this.