4

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!

m-sharp
  • 16,443
  • 1
  • 26
  • 26
  • The use the `ServiceLocator` to resolve specific objects only. If you do not need to override these on a per-window basis, I believe you can let sleeping dogs lie. Have you discovered that you *need* to override? – Jon Apr 01 '11 at 23:31
  • It seems like I will need to override these in order to have a Region Navigation Service and Region Manager and Region Registry per window. I can't see a way to make this work with the current design as it uses the ServiceLocator Singleton. – m-sharp Apr 04 '11 at 14:05
  • 1
    I believe that is a different issue than what the original question asks. See here: http://stackoverflow.com/questions/5276984/how-to-do-multiple-shells-in-my-prism-app-like-ms-office – Jon Apr 04 '11 at 14:11

2 Answers2

0

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

apprich
  • 144
  • 7
0

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.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72