MefContrib / MefContrib

User contributed extensions for the Managed Extensibility Framework (MEF)

Home Page:http://mefcontrib.codeplex.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CompositionDependencyResolver's globalContainer does not use GenericCatalog

barryschulz opened this issue · comments

Ex. construct a CompositionDependencyResolver using an aggregateCatalog that contains a GenericCatalog

Prior to the fix for issue #18, the globalCatalog was set to the CompositionDependencyResolver 's catalog argument and then used to construct the globalContainer. The globalContainer is then used as the ExportProvider for the container used as the service provider.

Since switching to a FilteredCatalog, it looks like none of the providers in the new container's AggregatingExportProvider know about the GenericCatalog. This results in generic parts not being found.

One solution is to create a CatalogExportProvider from the GenericCatalog (if it exists) and add it as an ExportProvider to the new container (in addition to the globalContainer).

//this.globalCatalog = catalog

this.completeCatalog = catalog;
this.globalCatalog = new FilteringCatalog(
     this.completeCatalog, new HasPartCreationScope(PartCreationScope.Global));

this.globalContainer = new CompositionContainer(this.globalCatalog, true, null);

Would this work?

        // Keep the original catalog
        this.completeCatalog = catalog;

        // Filter the global part catalog to a set of parts that define PartCreationScope.Global.
        this.globalCatalog = new FilteringCatalog(
            this.completeCatalog, new HasPartCreationScope(PartCreationScope.Global));
        this.globalContainer = new CompositionContainer(this.globalCatalog, true, null);

        // Filter the per-request part catalog to a set of parts that define PartCreationScope.PerRequest.
        this.filteredCatalog = new FilteringCatalog(
            this.completeCatalog, new HasPartCreationScope(PartCreationScope.PerRequest));