How to choose between MEF and any IoC container?

In which scenario should we use which? How to decide which one to choose? And under what circumstances would we decide to use both together?

I previously worked with Unity Container ( ).

+4
source share
4 answers

The difficult question is because the two do overlap to a certain extent.

I would say the following:

  • use any useful IoC if you are primarily concerned about dependency injection to decouple your components, for example. for the ability to be able to enter a layout instead (for testing)

  • MEF, , . " , ", (, Visual Studio: API, ). MEF .

MEF Unity MEF Unity, .

Ayende , MEF IoC.

+12

MEF , , , , , . MEF , IoC.

, IoC, , MEF, , .

+1

Glen Block ( MEF) :

+1

( , , ): IoC , - , MEF , .

, IoC :

For<ICarFactory>().Use<CarFactory>();

Whenever you want to use ICanFactory, you will receive CarFactory.

MEF is good for telling me all the car factories:

CheapCarFactory : ICarFactory
FamilyCarFactory : ICarFactory 
LuxuryCarFactory : ICarFactory

Etc.

0
source

Source: https://habr.com/ru/post/1778239/


All Articles