我第一次尝试使用 MEF,但我似乎无法确定应该在哪里创建我的AggregateCatalog
and CompositionContainer
. 我发现了很多例子来说明代码应该是什么:
var moduleCatalog = new AggregateCatalog(
new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly()),
new DirectoryCatalog(moduleDir));
var container = new CompositionContainer(moduleCatalog);
container.ComposeParts(this);
但现在我只需要知道把它放在哪里。它应该去:
- 在
App.xaml.cs
- 在
MainWindow.xaml
- 或在我的一个 ViewModel 中。
编辑:应该再用谷歌搜索一下,我想我找到了我想要的东西。