Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why exactly isn't MEF a DI/IoC container?

It's been said on the blogosphere and by Microsoft themselves that MEF isn't another IoC container.

OK...but why? It seems the same to me. Maybe it's not as good as Unity or Castle Windsor, but it still fits the definition, doesn't it?

Why isn't MEF an IoC Container like Unity or Castle Windsor?

like image 445
CVertex Avatar asked Oct 19 '08 15:10

CVertex


People also ask

Is MEF an IoC container?

No, it is otherwise. IoC is a broad concept and DI is the design pattern to implement the core of IoC. MEF is some form of DI, but it has not all fundamental features of IoC. MEF uses composition to find out the dependencies it needs to resolve.

What is IoC DI container?

The IoC container that is also known as a DI Container is a framework for implementing automatic dependency injection very effectively. It manages the complete object creation and its lifetime, as well as it also injects the dependencies into the classes.

Which IoC container is best?

You can waste days evaluating IOC containers. The top ones are quite similar. There is not much in this, but the best ones are StructureMap and AutoFac.

What are the advantages of IoC DI container?

Some benefits of using IoC. It is easy to switch between different implementations of a particular class at runtime. It increases the modularity of the program. It manages an object's life-cycle and configuration.


2 Answers

MEF has potential, but as a DI container, it lacks:

  1. Code as Configuration
  2. Auto Registration
  3. XML configuration (not so important to me)
  4. Custom Lifetimes
  5. Interception

Those things are pretty important.

For Lifestyle it lacks:

  1. Per graph
  2. Web Request Context
  3. Thread Context
  4. Session Context
  5. Pooled
  6. Scoped
  7. Custom Reference

References: - Mark Seemann's book "Dependency Injection in .NET"

like image 168
Tom Stickel Avatar answered Oct 22 '22 04:10

Tom Stickel


In my world DI is based on three dimensions, Object Composition, Lifetime Management, and Interception. This is what other full-blown DI containers, such as Unity, Castle Windsor, and Ninject facilitates. MEF only supports the one dimension, Object Composition. It is doing this quite well, but the remaining two dimensions are not supported in MEF.

like image 43
Mads Tjørnelund Toustrup Avatar answered Oct 22 '22 05:10

Mads Tjørnelund Toustrup