目錄(Catalogs)編程
MEF 特性編程模型的核心價值,擁有經過目錄動態地發現部件的能力。目錄容許應用程序輕鬆地使用那些經過 Export Attribute 註冊自身的導出。下面列出 MEF 提供的目錄。
var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
var catalog = new DirectoryCatalog("Extensions");
var catalog = new DirectoryCatalog("Extensions"); // 實現掃描的邏輯 catalog.Refresh();
var catalog = new AggregateCatalog( new AssemblyCatalog(Assembly.GetExecutingAssembly()), new DirectoryCatalog("Extensions"));
var catalog = new TypeCatalog(typeof(type1), typeof(type2), ...);
var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly()); var container = new CompositionContainer(catalog);