Load module inside module and general design discussion

Topics: Prism v2 - WPF 3.5
Jun 18, 2009 at 12:33 PM

I have some problem to undestand how load module, let's me explain my app :

Consider that Shell contains 3 regions : HeaderRegion, MenuRegion, MainRegion and FooterRegion.

I have

  • HeaderModule, MenuModule and FooterModule
  • 3 main module called MainModuleA, MainModuleB and MainModuleC
  • X basic modules called Module1, Module2, ... ModuleX
  1. Shell load HeaderModule, MenuModule and FooterModule
  2. At this time no module loaded in MainRegion
  3. MenuRegion contain a module that build a menu and send event when user change the selected item of the menu.
  4. For example user click on LoadModuleA in menu
  5. Question : should i subscribe to MenuChangedEvent via EventAggregator in ShellPresenter and then use ModuleCatalog.AddModule(typeof(MainModuleA)); and do the same thing when user click on LoadModuleB : ModuleCatalog.AddModule(typeof(MainModuleB)); is the best practice or there is an other way ?
  6. Question : The basics modules are used int the main modules (for example MainModuleA should load Module1, 3, 5 and MainModuleB should load Module 1, 2, 3, 4) how load module inside another module, can we declare regions in a module view ? for example in MainModuleA.MainView declare some specific region where module will be injected

Thanks a lot by advance

Jun 19, 2009 at 5:54 PM

Hi

 

I will try to answer your questions separately.

 

About clicking a menu item and loading another module

I assume your scenario consists in click a button from a module and loading a particular module. That module in turn, will show one of its views in the MainRegion.

If this is the case, you could set the module to be loaded on demand and load it when you click the button in the menu. You might do this in the Menu module, injecting the ModuleManager and using the moduleManager.LoadModule method. Then in the module’s initialize method, you could create an instance of the view you want to show in the MainRegion and add the view to the region (using ViewInjection or ViewDiscovery).

 

About loading modules

The above answer also deals with this topic. The Modularity QuickStarts for WPF show how modules can be loaded by other modules (just to make the concept clear, modules are not loaded inside other modules, they are just loaded and they are all part of the application).

Related to declaring regions in a module view, the answer is “yes”, this can be done. You can also create scoped regions (regions with their own RegionManager), but that depends on your requirements. To add a region inside a view, you can do it as you would in the Shell (you can check How to: Add a Region).

 

Remember, that modules have different views (amongst other things) which they inject into regions. This thread provides some more insight about this:

·         Confirmation of understanding

Please let me know if this helps.

 

Damian Schenkelman

http://blogs.southworks.net/dschenkelman