How to retrieve a bootstrapper exported type from another class?

Topics: Prism v4 - WPF 4
Sep 14, 2011 at 11:03 AM
Edited Sep 14, 2011 at 11:10 AM

Hello,

In one of my application service, I need to retrieve an exported type from another module which is exported on bootstrapper composition. The problem is that this service is in a different assembly than my bootstrapper and does not have any dependencies. I am using the MefBootstrapper.

 

How can I gracefully retrieve those types from another module?

 

Thanks.

Developer
Sep 14, 2011 at 3:30 PM

Hi,

Based on my understanding you could try decorating the class that contains the implementation of your service with the Export attribute. This way when the module is loaded, their services will be added to the container. Note that typically services are registered and retrieved from the container using common interface types as the "contract"; so, in order to achieve this scenario, you need to have the interface in a shared project (i.e. a project that is referenced throughout your other projects), but the project containing the concrete implementation of this interface does not need to be shared.

For example, in the StockTrader Reference Implementation, interfaces for shared services are placed in the StockTraderRi.Infrastructure project. An example of this can be seen in the Market module, which provides an implementation of IMarketFeedService, that is consumed in the PositionModule.

Also you might find the following blog post useful, which provides a sample of Prism, MEF, and Shared Services:

Prism 4 in Silverlight with MEF CompositionInitializer

Agustin Adami
http://blogs.southworks.net/aadami