棱镜,维修器和统一容器层次结构和多窗口WPF应用程序
我想构建一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将 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
我实际上需要做同样的事情,并且我想出了以下解决方案:
在导航到“子”区域之前,请执行以下操作:
这会在子区域上设置正确的导航服务。
当然,
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:
This sets the correct navigation service on the child region.
Of course,
childContainer
should have anIRegionNavigationService
in its own catalog, so that it will compose it properly.