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

What is the MEF method to get an existing exported value / object (not get Or Create) ?

Mar 17, 2012 at 7:05 AM
Edited Mar 17, 2012 at 7:07 AM

Here's how I would want it work

// should throw (or can return null) if container doesn't contain an instance matching the contract var x = container.GetExportedValue<T>(); var y = container.GetButDoNotCreate<T>();
// should return the object created in previous step

The difference is that this method won't create an instance if the container doesn't contain it. It is a pure-get. It should work for both shared and non-shared parts.. (given some unique way of identifying an instance)

I need it for my tests where I do not want the test code to create objects in the production container (if they are not created) just use existing ones. Only production code should add/remove objects to the container.

Is this possible ?