Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding an instance to a MEF container

How can you add an already created instance to a MEF container/cataloge to use when resolving Imports. I want the functionality that Unity gives with the RegisterInstance method on its containers.

like image 681
Cornelius Avatar asked Mar 04 '11 08:03

Cornelius


1 Answers

You can use the ComposeExportedValue function for this, like so:

var container = new CompositionContainer();
container.ComposeExportedValue<Application>("Application", Application.Current);
like image 136
alexn Avatar answered Sep 25 '22 13:09

alexn