【发布时间】:2012-02-29 07:05:39
【问题描述】:
我有一些插件作为 dll 文件。我的应用程序加载了 dll 并且运行良好。但是当我尝试删除旧插件并用新插件替换它时,它不允许这样做。因为它已由应用程序加载。我发现通过使用 appdomain 我们可以做到这一点。但我找不到使用 mef 的解决方案。
我需要一个可以在 mef 上运行的代码。下面是我用来加载插件的代码。
//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);
【问题讨论】: