Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining MEF and IoC container

I primarily use NInject as my IoC container, and is very happy with it - don't want to change that. But some things I want to import using MEF. The thing is, I want the imports to created by the IoC container as the imports can have dependencies to things that I've registered in the NInject IoC.

So, my question is: can I import the type of exports in some way, so I can hand it over to NInject for creation or is there an object factory of some kind that I can override in MEF?

like image 287
Einar Ingebrigtsen Avatar asked Apr 22 '10 12:04

Einar Ingebrigtsen


People also ask

Is MEF an IoC container?

Introduction. The Managed Extensibility Framework (MEF) has solved the common problems encountered when developing enterprise applications. It's a new library introduced in the . NET Framework 4.0, which is essentially an IOC container.

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. At SSW we use Autofac on most projects.

Why do we need IoC container?

The IoC container constructs an object of the selected class and also injects all the dependency objects via a constructor, a property, or a function at execution time and disposes it at a suitable time. This approach helps to create and manage objects manually.

What is IoC container and dependency injection?

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.


1 Answers

Autofac 2.1 integrates pretty well with MEF. See this post by Nicholas Blumhardt about how it works.

like image 174
Wim Coenen Avatar answered Oct 24 '22 15:10

Wim Coenen