Thursday, January 13, 2011

MEF TIP – How to initialize CompositionHost with all the assemblies contained in the application main XAP?

It’s a very a simple operation although not obvious (at least to me):

- Create an instance of the DeploymentCatalog class using the empty constructor. This gets the list of parts included in the manifest of the main XAP.

- Call CompositionHost.Initialize(deploymentCatalog, …)

If you are loading XAPs outside of MEF you must keep track of the assemblies you load and save that information, then create one AssemblyCatalog for each of then and merge them in a AggregateCatalog.

Have fun,