This project has moved. For the latest updates, please go here.

Using CompositionContainer and MEF

Feb 14, 2011 at 8:43 AM


I was looking into the section of 'Querying the CompositionContainer' in MEF sample documentation. Most of the examples uses this construct,

Lazy<Root> export = container.GetExport<Root>();
var root = export.Value

Now my basic question is, how do I get a handle to the container instance? I am defining my CompositionContainer in Bootstrapper class (Custom defined to be precise). So the container is accessible to my Bootstrapper class only:(.

Is there a way to get my CompositionContainer exported too? and use it decorating with property Import attribute??


// I have a Module A which has a class "SomeExportableClassFromSomeModule" decorated with Export attribute.

// I am trying to get a handle to that 'SomeExportableClassFromSomeModule' class from a Module B :: SomeClass

 // I have added all the modules in Bootstrapper as AggregateCatalog.Catalogs.Add(new AssemblyCatalog((typeof(ModuleA).Assembly))); etc.

    class SomeClass

        public Lazy<CompositionContainer>  container { get; set; }

        public SomeClass()  { 

           container.Value.GetExports<SomeExportableClassFromSomeModule>(); }      

Is this concept possible? I am unable export my container from Bootstrapper class?


Any pointers/links/snippets are highly appreciated.