In MEF, from the System.ComponentModel.Composition assembly, it is possible to create a hierarchy of containers and use parent exports for child containers.

 // Ρ€ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒΡΠΊΠΈΠΉ ΠΊΠΎΠ½Ρ‚Π΅ΠΉΠ½Π΅Ρ€ var parentContainer = new CompositionContainer(new TypeCatalog(typeof(ParentService))); // Π΄ΠΎΡ‡Π΅Ρ€Π½ΠΈΠΉ ΠΊΠΎΠ½Ρ‚Π΅ΠΉΠ½Π΅Ρ€ var childContainer = new CompositionContainer(new TypeCatalog(typeof(Service)), parentContainer); // использованиС Π΄ΠΎΡ‡Π΅Ρ€Π½ΠΈΡ… ΠΈ Ρ€ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒΡΠΊΠΈΡ… экспортов Ρ‡Π΅Ρ€Π΅Π· Π΄ΠΎΡ‡Π΅Ρ€Π½ΠΈΠΉ ΠΊΠΎΠ½Ρ‚Π΅ΠΉΠ½Π΅Ρ€ childContainer.GetExportedValue<IService>().DoWork(); childContainer.GetExportedValue<IParentService>().DoParentWork(); 

I am using MEF 2 from the Microsoft.Composition NuGet package. There was a need to create a hierarchy of containers. Is there the same opportunity here? I do the following:

 var parentContainer = new ContainerConfiguration() .WithPart<ParentService>() .CreateContainer(); // Как ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‚ΡŒ сюда Ρ€ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒΡΠΊΠΈΠΉ ΠΊΠΎΠ½Ρ‚Π΅ΠΉΠ½Π΅Ρ€? var childContainer = new ContainerConfiguration() .WithPart<Service>() .CreateContainer(); childContainer.GetExport<IService>().DoWork(); childContainer.GetExport<IParentService>().DoParentWork(); // Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅. Экспорт Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½ 

    1 answer 1

    As it turned out, MEF 2 does not support container hierarchy. Codeplex Documentation :

    There is no catalog concept, nor any β€œcontainer hierarchy” or composition scoping APIs.