MEF没有加载我的插件

时间:2015-09-01 20:47:44

标签: c# plugins reflection mef

我在C# with MEF中实现了一个非常小的插件系统。但是我的插件不会被加载。在Aggregate-Catalog我可以看到my plugin listed。但是,在我编写这些部分之后,插件列表中没有我的插件,我做错了什么?

以下是我的代码片段:

插件-装载机:

    [ImportMany(typeof(IFetchService))]
    private IFetchService[] _pluginList;
    private AggregateCatalog _pluginCatalog;
    private const string pluginPathKey = "PluginPath";
    ...

    public PluginManager(ApplicationContext context)
    {
        var dirCatalog = new DirectoryCatalog(ConfigurationManager.AppSettings[pluginPathKey]);
        //Here's my plugin listed...
        _pluginCatalog = new AggregateCatalog(dirCatalog);

        var compositionContainer = new CompositionContainer(_pluginCatalog);
        compositionContainer.ComposeParts(this);
     }
     ...

在这里,插件本身:

[Export(typeof(IFetchService))]
public class MySamplePlugin : IFetchService
{
    public MySamplePlugin()
    {
        Console.WriteLine("Plugin entered");
    }
    ...
}

0 个答案:

没有答案