Mab*_*lah 10 .net c# plugins mef updates
基类实例化MEF目录和容器,并将它们保存为类变量,以便稍后进行参照访问
public class FieldProcessor
{
private CompositionContainer _container;
private DirectoryCatalog dirCatalog;
public FieldProcessor()
{
var catalog = new AggregateCatalog();
//Adds all the parts found in the same assembly as the TestPlugin class
catalog.Catalogs.Add(new AssemblyCatalog(typeof(TestPlugin).Assembly));
dirCatalog = new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory + "Plugin\\");
catalog.Catalogs.Add(dirCatalog);
//Create the CompositionContainer with the parts in the catalog
_container = new CompositionContainer(catalog);
}
public void refreshCatalog()
{
dirCatalog.Refresh();
}
} ...
Run Code Online (Sandbox Code Playgroud)
这是我试图覆盖的插件.我的更新测试是,返回的stings输出到文本框,我更改了插件返回的字符串,重建并将其复制到插件文件夹中.但它不会更新正在运行的应用程序,直到我关闭并重新启动应用程序.
[Export(typeof(IPlugin))]
[ExportMetadata("PluginName", "TestPlugin2")]
public class TestPlugin2 : IPlugin
{
public IEnumerable<IField> GetFields(ContextObject contextObject, params string[] parameters)
{
List<IField> retList = new List<IField>();
//Do Work Return Wrok Results
retList.Add(new Field("plugin.TestPlugin2", "TestPluginReturnValue2"));
return retList;
}
}
Run Code Online (Sandbox Code Playgroud)
[ImportMany(AllowRecomposition=true)]
IEnumerable<Lazy<IPlugin, IPluginData>> plugins;
Run Code Online (Sandbox Code Playgroud)
小智 3
您是否AllowRecomposition为导入属性设置了参数?
AllowRecomposition
Gets or sets a value that indicates whether the property or field will be recomposed when exports with a matching contract have changed in the container.
Run Code Online (Sandbox Code Playgroud)
编辑:
DirectoryCatalog 不更新程序集,仅添加或删除: http://msdn.microsoft.com/en-us/library/system.componentmodel.composition.hosting.directorycatalog.refresh.aspx
解决方法: https ://stackoverflow.com/a/14842417/2215320
| 归档时间: |
|
| 查看次数: |
4237 次 |
| 最近记录: |