MEF查询组合容器
查询组合容器
当查询一个简单实例时返回null或者一个以上时会出异常。
GetExportedValue();
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");
GetExport();
Lazy<Root> export = container.GetExport<Root>();
var root = export.Value; //create the instance.
GetExportedValueOrDefault();
var root = container.GetExportedValueOrDefault<Root>(); // may return null