0

在我的 MEF 应用程序中,我计划从两种方式加载模块。

一种方法是这样的。

    protected override void ConfigureAggregateCatalog()
    {
        this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PEMDAS.ModuleInit).Assembly));
        this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));
        this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Infrastructure.ObservableCommand).Assembly));
        this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Security.SecurityModule).Assembly));
        this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Tests.ModuleInit).Assembly));
    }

另一个将在文件夹中查找程序集。我想这可以用这两种方式。我计划先加载文件夹,然后加载ConfigureAggregateCatalog.

4

1 回答 1

2

如果我正确理解您的问题,您想知道如何从文件夹中的 .dll 程序集中加载模块。这可以通过DirectoryCatalog来完成。

//First create directory catalog and load modules from .dlls.
var dirCatalog = new DirectoryCatalog(folderToSearch, "*.dll");
this.AggregateCatalog.Catalogs.Add(dirCatalog);

//Next load the rest of the modules.
ConfigureAggregateCatalog();
于 2012-09-12T21:12:03.827 回答