Shell and Module loading

Feb 23, 2009 at 7:32 AM
Hi list,
what i have:
My Shell Form and a hard wired UserControl within the Shell. This UC should act as may MainMenu

Is there any chance to load and run Modules from within this UserControl. I think ybout using 




moduleManager or stuff like this but have no idea how to get a reference to IModulManager.




Thanks in advance


Feb 23, 2009 at 6:31 PM

Hi Peter,


The following article explains how to load modules on demand using the IModuleManager interface:

·         How to: Load Modules on Demand


You could also check the Modularity QuickStarts shipped with the Prism v2 release to see different sample implementations.


Please let me know if this helps.


Mariano Converti

Feb 24, 2009 at 8:08 AM

Hi Mariano,

and thanks for your reply.

What i did is as follows.


Bootstrapper.cs :



override IModuleCatalog GetModuleCatalog()




ModuleCatalog catalog = new ModuleCatalog();



typeof(EmployeeModule), "EmployeeModule");



return catalog;



public Shell(IModuleManager moduleManager)





this.moduleManager = moduleManager;



this.moduleManager.LoadModule("EmployeeModule"); << here i get a error



Resolution of the dependency failed, type = "BaseShell.Shell", name = "". Exception message is: The current build operation (build key Build Key[BaseShell.Shell, null]) failed: At least one cyclic dependency has been found in the module catalog. Cycles in the module dependencies must be avoided. (Strategy type BuildPlanStrategy, index 3)
any idea?


Feb 24, 2009 at 12:15 PM
Hi, the problem is the 2nd parameter in the AddModule call.
This parameter refers to the dependencies of the module you are adding:

catalog.AddModule(typeof(EmployeeModule), "EmployeeModule");

So this means EmployeeModule depends on EmployeeModule. When you are using typeof to add modules, the module name is inferred from the type, so using the following would be correct:


I hope this helps,
Julian Dominguez

Feb 24, 2009 at 12:32 PM
thanks for you reply. this problem is solved but the next is already here.
if i use:


protected override IModuleCatalog GetModuleCatalog()




ModuleCatalog catalog = new ModuleCatalog();



//catalog.AddModule(typeof(EmployeeModule), InitializationMode.OnDemand);






return catalog;



this version, the in '




override void InitializeModules() in bootstrapper.cs is called an all is ok.


But if i use the other line 'catalog.AddModule(typeof(EmployeeModule), InitializationMode.OnDemand);'  i got a crash in Employee.


Initialize()  'The region manager does not contain the MainRegion region.'. It seems to me that regionmanager is initialized 'very' late.

In i make 



private void Window_Loaded(object sender, RoutedEventArgs e)







Feb 24, 2009 at 12:44 PM
I'm not sure I follow the code because it is strangely formatted.
Are you trying to load a module on demand when the shell window has finished loading?
Why do you need this / what is the scenario? Why make it on demand at all?

There is a timing thing here, and it is that the regions get registered after the CreateShell method in the bootstrapper has finished.
Also GetModuleCatalog and InitializeModules get called after the shell was created, so the modules should not be available at this point.

If you are trying to add a region into a window that is not the main shell, then you might want to explicitely set the RegionManager attached property on the window, in order for it to register it regions there, like in the following:

public MyWindow(IRegionManager regionManager)
  RegionManager.SetRegionManager(this, regionManager);

If these are not your issues, please provide more context so we can help you better.
Feb 25, 2009 at 7:17 AM

Hi Julian

and very sorry about that ugly example.

You are right, it was a timing problem. As soon is i add a buuton to Shell and put the 'this.moduleManager.LoadModule("EmployeeModule");' inside Button_Click the suff works.
Thanks a lot