Prism, ServiceLocator and Unity, as well as a multi-window WPF application

I want to create a WPF / Prism application where each top-level window is in its own user interface thread. This is pretty straight forward. I use Unity as my DI container and would like to create a container hierarchy. In the simplest case, the root container will be at the application level, and each window will have a child container. This is desirable since each window can have its own common objects covered by the child container.

I would like each window to have its own area manager from Prism, so I have no problems with cross-threads, since each window will have its own UI thread. I see that Region and RegionManager are using SingleClon ServiceLocator.Current. This is a problem because I would like RegionManager to use the container in which it was bound, which is not possible when using a static singleton. Ask one of you to face this problem and how do you get around it?

Thanks!

+4
source share
2 answers

You can have your Bootstrapper as a child container and register your types there. And let your ServiceLocater be at the application level that your Bootstrappers will call.

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

0
source

I really needed to do the same, and I understood the following solution:

Before moving to the "child" area, do the following:

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

This sets up the correct navigation service in the child area.

Of course, a childContainer must have an IRegionNavigationService in its own directory so that it compiles it correctly.

0
source

Source: https://habr.com/ru/post/1346314/


All Articles