棱镜,维修器和统一容器层次结构和多窗口WPF应用程序

发布于 2024-10-29 03:27:33 字数 369 浏览 2 评论 0原文

我想构建一个 WPF/Prism 应用程序,其中每个顶级窗口都位于其自己的 UI 线程中。这是相当简单的事情。我使用 Unity 作为我的 DI 容器,并希望创建容器的层次结构。在最简单的情况下,根容器将位于应用程序级别,每个窗口将有一个子容器。这是可取的,因为每个窗口都可以有自己的由子容器限定范围的共享对象。

我希望每个窗口都有自己的 Prism 区域管理器,这样我就不会遇到任何跨线程问题,因为每个窗口都有自己的 UI 线程。我看到 Region 和 RegionManager 使用 ServiceLocator.Current 单例。这是一个问题,因为我希望 RegionManager 使用其范围内的容器,而静态单例是不可能的。你们中有人遇到过这个问题吗?您将如何解决它?

谢谢!

I want to build a WPF/Prism application where each top level window is in its own UI thread. That is fairly straight forward to do. I am using Unity as my DI container and would like to create a hierarchy of containers. In the simplest case, the root container will be at the application level and each window will have a child container. This is desirable as each window can have its own shared objects scoped by the child container.

I would like each window to have their own region manager from Prism so that I don't have any cross threading issues as each Window will have its own UI thread. I see that the Region and RegionManager use the ServiceLocator.Current singleton. This is an issue because I would like the RegionManager to use the container it is scoped to which is not possible with a static singleton. Have any of you run into this issue and how would you work around it?

Thanks!

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

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

发布评论

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

评论(2

成熟稳重的好男人 2024-11-05 03:27:33

您可以将 Bootstrapper 作为子容器并在那里注册您的类型。并将您的 ServiceLocater 置于应用程序级别,它将调用您的 Bootstrappers。

更多信息关于; http://msdn.microsoft.com/en-us/library/ff649077.aspx

You can have your Bootstrapper as child container and register your types there. And have your ServiceLocater in the application level which will call your Bootstrappers.

more info about; http://msdn.microsoft.com/en-us/library/ff649077.aspx

一向肩并 2024-11-05 03:27:33

我实际上需要做同样的事情,并且我想出了以下解决方案:

在导航到“子”区域之前,请执行以下操作:

var childRegion = _childRegionManager.Regions["ChildRegion"];            
_childRegion.NavigationService = _childContainer.GetExportedValue<IRegionNavigationService>();
_childRegion.NavigationService.Region = _childRegion;

这会在子区域上设置正确的导航服务。

当然,childContainer 在它自己的目录中应该有一个 IRegionNavigationService,这样它才能正确地组合它。

I actually needed to do the same thing, and I figured out the following solution:

Before navigating to the "child" region, do the following:

var childRegion = _childRegionManager.Regions["ChildRegion"];            
_childRegion.NavigationService = _childContainer.GetExportedValue<IRegionNavigationService>();
_childRegion.NavigationService.Region = _childRegion;

This sets the correct navigation service on the child region.

Of course, childContainer should have an IRegionNavigationService in its own catalog, so that it will compose it properly.

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