Loop through Modules

Topics: Prism v2 - Silverlight 3
Nov 5, 2009 at 5:10 PM

Is there a way to loop through all configured modules?  We have a "Control Panel" screen that we want load on demand, this exists in the shell.  When the control panel is loaded I want to loop through all modules and request a list of items that each module wants added to the control panel.  The module might or might not have already been loaded so in pseudo code what I would like to do is:

for each mod in ModuleCatalog
  if not mod.Loaded then loadModule(mod.Name)
  dim l as list(of something)=mod.GetControlPanelList

Is this possible?



Nov 9, 2009 at 5:32 PM

Hi Heather,

The approach you are suggesting above is not the best in my opinion, as you would be tight coupling the modules. If I understand your scenario correctly, you want to add some items from different modules to your “Control Panel”. A possible approach to do this, could be using an EventAggregator event, and subscribe to it in each of the modules that should add something to the Control Panel. Then, each of them could add the required views to the “Control Panel” region.

As you explain the module might or might no have been loaded. Before publishing the event you should load the modules that have not been loaded. To get this done you can use code like this:

foreach (string m in ModuleStrings)
The code above will only load modules that have not been loaded, and modules that already have will suffer no side effects.

You can read more about loading modules on demand here.

Please let me know if this helps.

Damian Schenkelman

Nov 10, 2009 at 6:24 PM

OK, we can use that approach.  I would have tested to see that the module implemented a given interface before expecting to call to it to get a list of anything to try and reduce the coupling.  In your example is ModuleStrings a global variable (or something similar) that is built during the bootstrapper load?