我已经实现了一个基于C# with MEF
的非常小的插件系统。问题是,我的插件没有实例化。在Aggregate-Catalog
我可以看到my plugin listed
。但是,在我编写这些部分之后,插件列表中没有插件,我做错了什么?基于MEF的插件系统不能插件我的插件
这里是我的代码片段:
插件-装载机:
[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");
}
...
}
我复制你的代码中的控制台应用程序和它的工作没有问题。 –