Dynamic Modules with different Nested Regions

Topics: Prism v4 - Silverlight 4
Sep 12, 2010 at 11:26 AM

I have spent almost 2 weeks on the net trying to find a solution, but looks like either I am doing something really stupid, or Prism is not useful for such a decoupled applications i want to create.

I am trying to create an application that will have a base shell that has no knowledge of the modules or the way it handles its own views on the screen, but provide the services for the modules to register with it for activation.

As an example, think of a application for a clinic that can have different modules like: Patient Details, doctors, appointments, services etc. based on the logged in user some of these modules will be applicable for the user. when the user selects a module activation option on the shell, say Patients details, the region on the shell will load the container view of the patient details module and let it load its own views in the nested regions, and when other module is selected, it wil unload this first module and unregister all the nested regions and load the new module & its nested regions.

I have tried to make use of the infrastructure from John Papa's demo at Mix09, and it kind of works as long as my container view of these modules have no nested regions.

I was wondering if there is any reference implimentation that I can look in to to see how this can be done, or if some one can point me how I can achieve to unload the regions that gets registred with the shell's region manager inspite of me using the option to create a new regionmanager scope.

I am using Prism 4 drop 6 at the moment

Thanks & regards

Sep 14, 2010 at 4:01 AM

I am begning to wonder if I am the only one thinking of developing the application in such a decoupled way. I thought it was a common practice to develop applications like that, and I have been doing something like this in my own framework for years now.

Should I take it that Prism only works when we have well defined Ragions on the Shell and cannot be used when modules can themself define their own sub regions?


Sep 14, 2010 at 10:06 PM
Edited Sep 14, 2010 at 10:16 PM



Based on our understanding you need to create an application where the shell window has no knowledge on how the modules manage their assets (views, services, etc). So first of all, you could use the RegionManager from your modules to register their views into the main region. There two topics that might help in this scenario:

  1. If you consider that the RegionManager is not enough based on your requirements, you could take a look at Communication (see the Shared Services section) that could help you on creating a custom service.
  2. As a user could decide when a module is started, you could load your modules on demand: Module (see the Loading Modules on Demand section). as you do not want

 As you mentioned that your the views of your modules could provide different layouts, you could take a look at the following forums threads and MSDN documentation section where this topic is treaded:

One possible approach in Prism for removing all the views of a particular module might be to create a main view with a region (it could be scoped) where all views of the module are added, so you could remove/deactivate the main view from the region manager. If you need guidance on how to remove a view from a region, you could check the following Quickstart:

I know that you are using Prism v4, but just in case, you could take a look at the Damian Schenkelman’s Blog post, which describes a memory leak using scoped regions:

As for how to notify to the application that a new view has been added to the Main Region, I think there is not something implemented in Prism out-the-box. But you could extend the Region class to notify when a view is added (for example using EventAggregator).

In addition, the following quickstarts & reference implementation could help as a reference:

Please let me know if this helps.

Fernando Antivero

Sep 15, 2010 at 5:07 PM


Thanks for your reply, these are indeed some very useful links that you have provided. It took me a while to go through them, but did learn a lot from these links.

"Too many regions in my shell" is in perticular very close to what I was looking at, but I was not exactly able to get this working in my previous try when I tried to create a scoped reagion for my modules.

in nutshell this is what I tried.

- Created a Shell with one "ModuleRegion" where my modules would register its container view.

- Created a container view  of ModuleX say "ViewX" with some regions for my module and in the module activation added this to the shells's "ModuleRegion" with CreateRegionManagerScope = true.

- when a different module ModuleY is activated, I unregister the earler module container view using shellModuleRegion.Deactivate(ViewX) and shellModuleRegion.Remove(ViewX)

- Now I add the container view of ModuleY say ViewY which has its own reagions

It works fine up to this point, but when I re activate the ModuleX, I end up getting the following error in the big exception stack trace:"Region with given name already registred:".

Looks like shell somehow gets registred with the internal nested regions of ViewX eventhough its created with the scoped region and after I deactivate and removed it.

do you see something wrong in my approach.



Sep 21, 2010 at 7:28 PM
Edited Sep 21, 2010 at 7:29 PM


I’ve read all steps that you listed and they seem to be correct. The only thing is that you could avoid to deactivate the ViewX, since it is not necessary, but it is just a detail.

Some time ago, I created an spike in Prism v2, that you could download from here. This spike is using scoped regions and you could remove/add views.

If you download this spike, you could compare it with your scenario.

I hope this helps,

Fernando Antivero