【发布时间】:2014-01-15 14:00:41
【问题描述】:
我在我的应用程序中使用 MEF 来加载一些简单的插件。每个插件由一个 ViewModel 和一个对应的 View 组成。
我能够成功创建此类插件的 ViewModel 实例,但是 Caliburn.Micro 说它无法找到它的视图。插件中的 ViewModel 被称为 SimpleValueDisplayViewModel 和视图 SimpleValueDisplayView,具有相同的命名空间。
我的引导程序中的相关代码:
public class MefBootstrapper : Bootstrapper<ShellViewModel>
{
protected override void Configure()
{
string pluginPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins");
if (!Directory.Exists(pluginPath))
Directory.CreateDirectory(pluginPath);
var catalog = new AggregateCatalog(
AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()
.Concat(new ComposablePartCatalog[] { new DirectoryCatalog("Plugins")})
);
_container = new CompositionContainer(catalog);
var batch = new CompositionBatch();
batch.AddExportedValue<IWindowManager>(new WindowManager());
batch.AddExportedValue<IEventAggregator>(new EventAggregator());
batch.AddExportedValue(_container);
_container.Compose(batch);
}
}
我是否需要以某种方式通知 Caliburn.Micro MEF 在“插件”目录中找到的程序集?
编辑:我尝试覆盖 SelectAssemblies 并将“插件”目录中的所有程序集添加到 AssemblySource.Instance。但是,然后我遇到了 MEF 两次查找程序集的问题,这反过来又在我实例化 ViewModel 时产生了问题。
【问题讨论】:
-
视图是嵌入在插件程序集中的xaml文件?
标签: wpf mvvm mef caliburn.micro