Tuesday, 6 January 2015

How MEF is different from DI/IOC?

They do overlap each other somewhere. But end goal of both of these concepts are completely different. To understand these 2 concepts we will take a scenario. We have 2 requirements:

  1. The application should be a tired application and each tier should be decoupled from each other for better reusability and maintainability.
  2. The application should provide a facility of exporting data in to different formats. External vendors should be able to plug in their own mechanism into the application.


For requirement 1 , goal is decoupling while for requirement 2 goal is extensibility.


DI/IOC
MEF
Decoupling
YES

Extensibility

YES
Integrate Known Things
YES

Integrate UnKnown Things

YES
Automatic discovery

YES
Registration
YES

Discovery

YES
Compile Time
YES

Run Time

YES

In DI/IOC registration of classes is done in configuration file while in MEF automatic discovery take place.  So that DI/IOC is compile time and MEF is runtime.
















Here for Decoupling you can use Unity Application Block and Windsor Container framework or anything similar.

No comments:

Post a Comment