CompositionContainer 公開了一部分獲取導出、導出對象以及二者集合的重載。ide
var container = new CompositionContainer(new AssemblyCatalog(typeof(Program).Assembly)); Root partInstance = container.GetExportedValue<Root>();
[Export("my_contract_name")] public class Root { } var container = new CompositionContainer(new AssemblyCatalog(typeof(Program).Assembly)); Root partInstance = container.GetExportedValue<Root>("my_contract_name");
Lazy<Root> export = container.GetExport<Root>(); var root = export.Value; //create the instance.
var root = container.GetExportedValueOrDefault<Root>(); // may return null