MEF中目录组件Catalog
- AssemblyCatalog:表示从程序集中搜索部件的目录。
- DirectoryCatalog:表示从文件系统的指定路径中,搜索程序集,从而搜索部件。
- TypeCatalog:表示从指定的类型集合中,去搜索相应的部件。
- AggregateCatalog:聚合目录,可以添加上面所说的所有目录,从而进行多方面的部件搜索。
示例:
var assemblyCatalog = new MEF.AssemblyCatalog(typeof(Program).Assembly); var directoryCatalog = new MEF.DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory + "\\Parts", "*.dll"); var typeCatalog = new MEF.TypeCatalog(typeof(Class6), typeof(Class7)); var aggregateCatalog = new MEF.AggregateCatalog(assemblyCatalog, directoryCatalog, typeCatalog); _container = new MEF.CompositionContainer(aggregateCatalog); var exports = _container.GetExports<object>(); foreach (var exportValue in exports) { Console.WriteLine(exportValue.Value.GetType()); }