Accessing the Catalog

Aug 27, 2010 at 4:12 PM

How do you get reference to the Catalog from other parts of your application. I want to manually Compose an Exported Value, however I do not have reference to the Catalog. Should it not be composed in the catalog by default, so that MEF can inject the catalog into any objects that need it?

Aug 27, 2010 at 9:46 PM

You can export the catalog you create in your main class and then import it in the other parts of your app that want to utilize it.

You can also create a global static that holds the main catalog.

You can also use Unity or some other IoC Container to inject the container into your other class instances.

In my app, I create a class that has one member that holds the container.  I declare an [Export] member instance of that class.  I create an instance of this class, create the container, set the property of my class to the new container.  Then I compose myself.  All objects created as part of my compose can import the container class.