Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between MEF, EntLib and Prism

I have a relatively basic question but more than anything just need some clarity really, I have been using Prism (Composite Application Guidance) to create a WPF MVVM desktop application in C#, this bit I am all clear about (or so I thought) along with IoC and Module based architecture etc. At the same time I have started using MEF and realise that there is a kind of grey area between the two (I have found and read a number of articles/blogs on hosting MEF Extensions in IoC containers and the like.

However....recently I have started looking at Enterprise Library 5 and this is whats led to my confusion. Where do they all fit together? So Prism uses DI with a Module based architecture... EntLib uses Di with an Application Block type architecture... and MEF doesn't use DI at all? Does this mean that EntLib and Prism are entirely separate architectual methods or that one is a subset of the other? Also could MEF be used with either/both?

Any explanation would be most welcome.

Many thanks

like image 682
jameschinnock Avatar asked Nov 11 '10 08:11

jameschinnock


2 Answers

I, too, was puzzled by the difference between IoC and MEF. The simplest way I found to describe them, was this:

MEF is for discovering and instantiating something you don't know about.

IoC is for requesting something you do know about.

A little bit of context. MEF will always instantiate the import that you request at least once. You are not capable of creating it yourself, and putting it into the catalogue ready to be used. MEF is responsible for creating and satisfying the imports. Dynamically loaded DLLs, where you don't know which DLLs are arriving, is a good example.

IoC on the other hand - you request an implementation from the current library, and you are given one. But you are also responsible for ensuring that an implementation exists.

IoC is for dependency injection. MEF is for extensibility.

like image 110
Josh Smeaton Avatar answered Oct 13 '22 14:10

Josh Smeaton


Take a look at these 2 posts:

  • Should I use MEF for my general IoC needs?
  • Prism and MEF

As to Enterprise Library, in v5.0 we've made it container-agnostic. Even though Enterprise Library ships with Unity container out-of-the-box, it is architected to work with any container of your choice or MEF. You do need to provide an appropriate configurator (see info on configurators at the end of this summary)

like image 3
Grigori Melnik Avatar answered Oct 13 '22 13:10

Grigori Melnik