This project has moved and is read-only. For the latest updates, please go here.

Access default container from another module?

Dec 10, 2010 at 7:02 PM

This is a wpf application.

Everything started off fine. I have my mef bootstrapper that creates my default container. My skins and themes are being injected properly and my logging is now working. So it is time to add data.
I built a generic repository and added the references from mefcontrib to get the open generics working.
Now I built a second container to hold the generic containers.

I go to GetExportedValue and bam! No valid exports were found that match the constraint. Hum.. Those constraints are in my default container.

How do I go about merging my containers together or get an instance of the default container?
I read some posts that said you need to export the default container then import it, but I am not really sure how to do that.

I think I may be going about this wrong as well. Should I be making new containers every time I need to access data?

ResourceSearchSpecification specification = new ResourceSearchSpecification(1, 1);

// Create the container
var container = GenericCatalogContext.CreateContainer();
// Get the GenericRepositoryHelper object
var repositoryHelper = container.GetExportedValue<GenericRepositoryHelper>();

    .ToDictionary(r => r.Name, r => r.Value)

public class GenericCatalogContext
    public static CompositionContainer CreateContainer()
        // Create source catalog
        var typeCatalog = new TypeCatalog(typeof(GenericRepositoryHelper));

        // Create catalog which supports open-generics, pass in the registry
        var genericCatalog = new GenericCatalog(new GenericContractRegistry());

        // Aggregate the both catalogs
        var aggregateCatalog = new AggregateCatalog(typeCatalog, genericCatalog);

        // Create the container
        return new CompositionContainer(aggregateCatalog);
public class GenericRepositoryHelper
    public IRepository<Resource> ResourceRepository { get; set; }