我们有许多产品可以共享常见的DLL。对于产品,我想指出要包含在目录中的特定DLL列表。我知道我可以这样做:
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(MainWindow).Assembly));
string fullPath = Path.Combine(@"D:\Folder\With\Plugins", "SomePlugin.dll");
Assembly dll = Assembly.LoadFile(fullPath);
ComposablePartCatalog assemblyCatalog = new AssemblyCatalog(dll);
catalog.Catalogs.Add(assemblyCatalog);
_container = new CompositionContainer(catalog);
_container.ComposeParts(this);
在每个特定文件的中间部分循环是最好的方法吗?
答案 0 :(得分:0)
MEF提供 DirectoryCatalog 。您所要做的就是指向包含插件的目录,它将处理其余部分,无需循环。像这样:
string fullPath = Path.Combine(@"D:\Folder\With\Plugins");
var catalog = new DirectoryCatalog(fullPath);
_container = new CompositionContainer(catalog);
_container.ComposeParts(this);