This project has moved. For the latest updates, please go here.

How does MEF know which implementation to use?

Jan 21, 2011 at 8:50 AM



I really am stuck with this one.  If I have a ClassA that has a ctor with parameters of IClassB. And I have two implementation of IClassB.

How does MEF know which one to pick for the injection?


I am particulary speechless by this example:

The ctor of GamesListViewModel takes

public GamesListViewModel(IGamesModel model)

But there are two IGamesModel implementation. The real one and a Mocked one. How does MEF know to pick the Mocked one if I run the silverlight unit test project and how does it know to pick the real one if I run the real application? I just can't see how that works, and the used attributes seem to be exactly the same.

Many Thanks,

Jan 25, 2011 at 2:13 PM


I'm not sure about this example, but the general answer is that MEF is a container and something in the startup would place one or the other, but not both the parts into the container. IOW, in the test initialization, the mock one is placed in the container, and in the real app run, the normal one is