Difference between MEF and DI / IOC
S.NoMEFDI / IOC1Abbreviation:
MEF stands for Managed Extensibility FrameworkAbbreviation:
DI / IOC stands for Dependency Injection and Inversion Of Control
Managed Extensibility Framework (MEF) is a component of .NET Framework 4.0 for creating lightweight, extensible applications. It allows application developers to discover and use extensions with no configuration required. It also lets extension developers easily encapsulate code and avoid fragile hard dependencies. MEF not only allows extensions to be reused within applications, but across applications as well. MEF was introduced as a part of .NET 4.0 and Silverlight 4.Meaning:
Dependency injection is a software design pattern that allows a choice of component to be made at run-time rather than compile time. This can be used, for example, as a simple way to load plugins dynamically or to choose mock objects in test environments vs. real objects in production environments. This software design pattern injects the dependent element (object or value etc) to the destination automatically by knowing the requirement of the destination.Inversion of Control usually refers to the "containers" while Dependency Injection refers to the actual pattern.DI is a form of IoC.Dependency injection is the main method to implement Inversion of Control.
3Where it can be used ?
MEF is useful for dynamic dependencies.Where it can be used ?
IOC is most useful with Static dependencies
4Used for Known / Unknown parts:
MEF is for discovery of unknown parts.Used for Known / Unknown parts:
IOC is for registration of known parts.
5Best choice for 3rd party controls or not:
When working with/for 3rd party dlls , MEF is more the best choice.Best choice for 3rd party controls or not:
When working with/for 3rd party dlls , IOC is not the best choice.
6Swapping DLLs at runtime possible or not:
If we have two dlls, taking a decision at runtime to swap the two is possible using MEF.Swapping DLLs at runtime possible or not:
If we have two dlls, taking a decision at runtime to swap the two is not possible using IOC.
7Plug-in versioning problem:
Plug-in versioning problem is not there in MEFPlug-in versioning problem:
Plug-in versioning problem is there in IOC