Prism / MEF - 一旦我的应用程序运行,我稍后如何添加到我的 AggregateCatalog 中?

发布于 2024-10-21 01:59:55 字数 304 浏览 6 评论 0原文

基本上,我有以下场景:

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

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

Basically, I have the following scenario:

  1. User runs application
  2. The Bootstrapper loads the "Modules" directory into the AggregateCatalog.
  3. My navigation menu is built
  4. The user clicks refresh
  5. The app downloads a new module and copies it into the Module directory.

I somehow need to be able to add in the new module to my AggregateCatalog and update my navigation menu. I figure a "AllowRecomposition" is necessary, but how do I actually add the new assembly to my AggregateCatalog after my app is already running?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘亓 2024-10-28 01:59:55

如果导入 AggregateCatalog,您可以从 ViewModel 中(或您想要添加到其中的任何其他位置)访问它。

[Import()]
private AggregateCatalog _aggregateCatalog;

...

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


NOTE: If the Assembly would affect any Import or ImportMany statements, they must allow for recomposition or you will get an exception. For example, if your assembly contains another IFooService export...

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

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


NOTE: You will trigger OnImportsSatisfied if you implemented the IPartImportsSatisfiedNotification interface again, so ensure that your application does not have issues because of this.

If you import the AggregateCatalog you can access it from within your ViewModel (or wherever else you want to add to it.

[Import()]
private AggregateCatalog _aggregateCatalog;

...

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


NOTE: If the Assembly would affect any Import or ImportMany statements, they must allow for recomposition or you will get an exception. For example, if your assembly contains another IFooService export...

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

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


NOTE: You will trigger OnImportsSatisfied if you implemented the IPartImportsSatisfiedNotification interface again, so ensure that your application does not have issues because of this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文