1

基本上,我有以下情况:

  1. 用户运行应用程序
  2. Bootstrapper 将“模块”目录加载到 AggregateCatalog 中。
  3. 我的导航菜单已建成
  4. 用户点击刷新
  5. 该应用程序下载一个新模块并将其复制到模块目录中。

我不知何故需要能够将新模块添加到我的 AggregateCatalog 并更新我的导航菜单。我认为“AllowRecomposition”是必要的,但是在我的应用程序已经运行后,如何将新程序集实际添加到我的 AggregateCatalog 中?

4

1 回答 1

1

如果你导入 AggregateCatalog,你可以从你的 ViewModel 中访问它(或者你想添加到它的任何地方。

[Import()]
private AggregateCatalog _aggregateCatalog;

...

private void SomeFunc()
{
    _aggregateCatalog.Catalogs.Add(...);
}


注意:如果程序集会影响任何 Import 或 ImportMany 语句,它们必须允许重新组合,否则您将获得异常。例如,如果您的程序集包含另一个IFooService导出...

//Exception Thrown
[ImportMany(typeof(IFooService))]
private IEnumerable<IFooService> _myFooServices;

//No Exception Thrown
[ImportMany(typeof(IFooService), AllowRecomposition = true)]
private IEnumerable<IFooService> _myFooServices;


注意:OnImportsSatisfied如果您再次实现该IPartImportsSatisfiedNotification接口,您将触发,因此请确保您的应用程序不会因此而出现问题。

于 2011-03-08T22:01:00.420 回答