2014-11-13 1 views
3

Так я мой каталог каталога создан показано ниже:Как создать DirectoryCatalog, которая будет искать другие каталоги плагин

DirectoryCatalog directoryCatalog = new DirectoryCatalog(@".\Plugins"); 
var catalog = new AggregateCatalog(directoryCatalog); 
var container = new CompositionContainer(catalog); 
container.ComposeParts(this); 

Что будет найти .dll в моей Plugins папки, которые соответствуют моим критериям импорта. Теперь, чтобы предотвратить столкновение ссылок в моих плагинах, я хотел бы поместить каждый плагин в отдельную папку.

например.

Плагины -> Plugin1 -> plugin1.dll

 -> Plugin2 -> plugin2.dll 

Но мой DirectoryCatalog не находит эти плагины. Можно ли это реализовать или сделать мои библиотеки модулей должны быть в том, что указанный .\Plugins папке

ответ

11

Вы можете решить проблему путем добавления нескольких DirectoryCatalogs к AggregateCatalog.Catalogs собственности, как это:

var catalog = new AggregateCatalog(); 
// iterate over all directories in .\Plugins dir and add all Plugin* dirs to catalogs 
foreach (var path in Directory.EnumerateDirectories(@".\Plugins", "Plugin*", SearchOption.TopDirectoryOnly)) 
{ 
    catalog.Catalogs.Add(new DirectoryCatalog(path)); 
} 

_container = new CompositionContainer(catalog); 
this._container.ComposeParts(this); 
+0

Блестящий! спасибо – user1