MEF create object explicitely
I am trying to create objects explicitely, similar to Spring ApplicationContext.getBean() method which creates objects with all the dependencies initialised within that object, I am not aware about MEF much , I tried searching web for the same but could not find the method to explicitely invoke creation of object with all its dependencies initialised,
Does anybody know the method which allows explicitely creating objects with all of its imports initialised ?
Thanks in advance,
ExportedType instance = compositionContainer.GetExportedValue<ExportedType>();
Where compositionContainer is your CompositionContainer instance and ExportedType is the type that you want to create/get an instance for.
How can you get an instance of CompositionContainer? Use the following code once:
CompositionContainer compositionContainer = CompositionHost.Initialize(catalog);
Where catalog is your MEF catalog (usually an instance of AggregateCatalog).