Mar 23, 2010 at 3:44 AM
Edited Mar 23, 2010 at 4:44 PM
I have a question that I am hoping the community can help me resolve...
My shell application is comprised of a "MainRegion" which is visually represented by a TabControl. The TabControl's two TabItems are each populated by instances of views from two separate modules (let's call them ModuleOne and ModuleTwo). In a
separate module, (let's call this one TreeModule) I have a TreeControl view and all the necessary logic to fill the tree view with data.
I would like the views from ModuleOne and ModuleTwo to each display an instance of the TreeModule’s view. I have declared a Region (inside a ContentControl) in each of the views of ModuleOne and ModuleTwo. This is where I would like to load an instance
of TreeModule view. My question is about the proper way to accomplish this.
My requirement is to maintain a clear separation between the TreeModule the other Modules (I believe the TreeModule should be reusable for future applications).
I have started by creating a scoped region manager in the Initialization method of ModuleOne and ModuleTwo. It seems that I now need to add an instance of the TreeModule's view to the proper region within the scoped region manager(s).
How can I do this without directly referencing the TreeModule from within ModuleOne and ModuleTwo? In order to resolve using the Unity, I would need to at least have access to the view's interface. I have considered adding the Interface
for the view to the common infrastructure project. Then I could use it to resolve using the container.
Would this be the correct solution?
Also, in many of the examples I have seen online, modules (like my TreeModule) often add themselves to regions within the injected RegionManager. In my current situation, this causes an error as the Shell’s Region Manager does not have a named region
for the Tree View (because the views within the TabItems do). This leads me to believe I should be registering the scoped region managers and injecting those into the TreeModule? However, that seems incorrect as well because I believe the application should
have only 1 instance of the module.
I am confused! Any help will be really appreciated.
Here is a code snippet of the Init Method for ModuleOne (variable names changed for simplicity)
// ModuleOne's Init Logic
//(ModuleOne's view represents one TabItem in a TabControl)
_container.RegisterType<ISomeModel, SomeModel>(new ContainerControlledLifetimeManager());
var mainView = _container.Resolve<ISomeView>();
// this sets the datacontext of the view to the viewmodel
// add to main region and create a scoped region manager for the nested regions
IRegionManager scopedRegionManager =
_regionManager.Regions["MainRegion"].Add(mainView, null, true);
// adding treeview to scoped region
// I have to directly reference the TreeModule in ModuleOne to get these
// types and that seems like too much coupling
var scopedTreeView = _container.Resolve<ITreeView>();