卸载在MEF一个DLL文件 [英] Unloading a dll file in mef
问题描述
我有一些插件,dll文件。我的应用程序加载DLL,它运行良好。但是当我尝试删除旧的插件,以及一个新的插件更换它不允许做我的。因为它已经被应用程序加载。我发现,通过使用AppDomain中,我们可以做到这一点。但我不能够找到其中使用MEF的解决方案。
我需要它可以在MEF运行代码。下面是我的代码,用于加载插件。
//创建目录总的一个实例。它聚合其他目录
变种aggregateCatalog =新AggregateCatalog();
//建设,其中部分将提供
VAR目录路径=路径plugins文件夹的目录路径;
$ B $使用目录目录
变种directoryCatalog =新DirectoryCatalog从指定的路径可用的dll b //加载件(目录路径,* .dll文件);
//添加到总目录
aggregateCatalog.Catalogs.Add(directoryCatalog);
//克里特岛组成容器
变种集装箱=新CompositionContainer中(aggregateCatalog);
//可组合的部件都在这里创建即导入和导出组件组装这里
container.ComposeParts(本);
我发现,通过使用AppDomain中,我们可以做到这一点。但我不能够找到其中使用MEF的解决方案。
块引用>
不幸的是,这不是由MEF支持。 MEF是为应用程序的可扩展性而设计的,而不是支持卸载,并在运行时替换代码通用插件系统。
使这项工作将是唯一的办法一个单独的AppDomain中使用MEF和卸载的AppDomain作为一个整体。在CLR本身具有卸卸比在该组件打开整个应用程序域之外的加载的程序集的支持。
I have some plugins as dll files. My application loads the dll and it runs fine. but when I try to delete the old plugin and replace it with a new plugin it doesn't allow to do me. as it has been loaded by application. I have found that by using appdomain we can do that. but I am not able to find a solution in which mef is used.
I need a code which can run on mef. Below is my code which is used to load plugins.
//Creating an instance of aggregate catalog. It aggregates other catalogs var aggregateCatalog = new AggregateCatalog(); //Build the directory path where the parts will be available var directoryPath = "Path to plugins folder"; //Load parts from the available dlls in the specified path using the directory catalog var directoryCatalog = new DirectoryCatalog(directoryPath, "*.dll"); //Add to the aggregate catalog aggregateCatalog.Catalogs.Add(directoryCatalog); //Crete the composition container var container = new CompositionContainer(aggregateCatalog); // Composable parts are created here i.e. the Import and Export components assembles here container.ComposeParts(this);
解决方案i have found that by using appdomain we can do that. but i am not able to find a solution in which mef is used.
Unfortunately, this is not supported by MEF. MEF was designed specifically for application extensibility, not as a general purpose plugin system which supports unloading and replacement of code at runtime.
The only way to make this work would be to use MEF within a separate AppDomain, and unload the AppDomain as a whole. The CLR itself has no support for unloading a loaded assembly other than unloading the entire AppDomain in which the assembly is opened.
这篇关于卸载在MEF一个DLL文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!