【发布时间】:2015-09-02 13:40:16
【问题描述】:
我已经基于C# with MEF 实现了一个非常小的插件系统。问题是,我的插件都没有实例化。在Aggregate-Catalog 我可以看到my plugin listed。但是,我将这些部分组合起来后,插件列表中没有我的插件,我做错了什么?
这是我的代码的 sn-p:
插件加载器:
[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");
}
...
}
【问题讨论】:
-
我在控制台应用程序中复制了您的代码,并且没有问题。
标签: c# plugins reflection mef