67

It's been said on the blogosphere and by Microsoft themselves that MEF isn't another IoC container.

OK...but why? It seems the same to me. Maybe it's not as good as Unity or Castle Windsor, but it still fits the definition, doesn't it?

Why isn't MEF an IoC Container like Unity or Castle Windsor?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CVertex
  • 17,997
  • 28
  • 94
  • 124
  • 2
    You could at least let me keep an upvote for the link to the herding code interview :) – Kev Feb 02 '09 at 02:09
  • Sure Kev. Sorry bout that, but the Glen blocks answer in hanselminutes was alot more detailed. The interview you posted was good, but left me with more questions than answers. – CVertex Feb 02 '09 at 02:26
  • 1
    We covered this in a recent hanselminutes episode. http://www.hanselminutes.com/default.aspx?showID=166 – Glenn Block Feb 01 '09 at 08:11

2 Answers2

11

MEF has potential, but as a DI container, it lacks:

  1. Code as Configuration
  2. Auto Registration
  3. XML configuration (not so important to me)
  4. Custom Lifetimes
  5. Interception

Those things are pretty important.

For Lifestyle it lacks:

  1. Per graph
  2. Web Request Context
  3. Thread Context
  4. Session Context
  5. Pooled
  6. Scoped
  7. Custom Reference

References: - Mark Seemann's book "Dependency Injection in .NET"

user247702
  • 23,641
  • 15
  • 110
  • 157
Tom Stickel
  • 19,633
  • 6
  • 111
  • 113
8

In my world DI is based on three dimensions, Object Composition, Lifetime Management, and Interception. This is what other full-blown DI containers, such as Unity, Castle Windsor, and Ninject facilitates. MEF only supports the one dimension, Object Composition. It is doing this quite well, but the remaining two dimensions are not supported in MEF.

  • 3
    Lifetime management is now significantly improved in MEF 2.0 in 4.5 / 4.0 on nuget in addition to having a convention based config model. Interception is not there, though MEF Contrib does have an extension for AOP / Interception. – Glenn Block Jan 10 '13 at 06:17