Adding referenced exports in Bootstrapper

Topics: Prism v4 - Silverlight 4
Dec 14, 2010 at 10:36 AM


In my Shell I have references to a few dll's that have a few Exports within them. To explain better here is how it is

  • Shell (which has App.xaml and that runs the Bootstrapper) has following references
    • ComponentA with a few exports
    • ComponentB with a few exports

In order for the exports to get into the AggregateCatalog in my MefBootstrapper I'm having to do this

public class Bootstrapper : MefBootstrapper
{ protected override void ConfigureAggregateCatalog()

            AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));
            AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ComponentA).Assembly));
            AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ComponentB).Assembly));

I would have thought that the exports in the referenced dll's (set to CopyLocal=True) should have automatically got into the AggregateCatalog. In fact event the exports in Shell should do. Is there a reason why it doesnt do it automatically, like how it does in a downloaded Module (xap)? In fact Shell is also a xap so in effect it should be doing it by itself. I shouldnt be needing to call this as well?


AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));

I think it would be good if it does this automatically in the ConfigureAggregateCatalog in the MefBootstrapper.

Dec 14, 2010 at 5:34 PM


Thank you for your feedback. The reason you have to register your assemblies in the AggregateCatalog in the override ConfigureCatalog method is because, in order to be able to compose parts, MEF needs the corresponding catalogs to be added to a container, called CompositionContainer. From documentation: “The core of the MEF composition model is the composition container, which contains all the parts available and performs composition. (That is, the matching up of imports to exports.) The most common type of composition container is CompositionContainer…

In Prism, when MEF´s CompositionContainer is created, the AggregateCatalog that is added to it is empty, so you cannot perform any composition as long as you don't add any catalog to the AggregateCatalog.

When you load a module remotely using MEF, "Under the hood, Prism applications using MEF use MEF's DeploymentCatalog class to download .xap files and discover the assemblies and types within those .xap files. The MefXapModuleTypeLoader adds each DeploymentCatalog to the AggregateCatalog.". That said, when loading a module remotely, Prism internally adds a catalog to the AggregateCatalog, just like you do in the bootstrapper.

You might find more information about this in the following links:

· Prism documentation: Chapter 2: initializing Prism Applications and Chapter 3: Managing Dependencies Between Components

· MEF documentation: Managed Extensibility Framework Overview and more specifically this section.

I hope you find this information useful.


Miguel Bronzovic