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 

 

IModuleManager

 

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

 

 

 

Thanks in advance
 Peter

 

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

http://blogs.southworks.net/mconverti

Feb 24, 2009 at 8:08 AM

Hi Mariano,

and thanks for your reply.

What i did is as follows.

 

Bootstrapper.cs :

protected

 

override IModuleCatalog GetModuleCatalog()

 

{

 

ModuleCatalog catalog = new ModuleCatalog();

 

catalog.AddModule(

typeof(EmployeeModule), "EmployeeModule");

 

 

return catalog;

 

}

Shell:
public Shell(IModuleManager moduleManager)

 

{

InitializeComponent();

 

this.moduleManager = moduleManager;

 

 

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

 

}

ErrorMessage:
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?

Thanks
Peter

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:

catalog.AddModule(typeof(EmployeeModule));

I hope this helps,
Julian Dominguez
http://blogs.southworks.net/jdominguez

Feb 24, 2009 at 12:32 PM
Hi,
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);

 

catalog.AddModule(

typeof(EmployeeModule));

 

 

return catalog;

 

 

}
this version, the in '

 

protected

 

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 Shell.cam.cs i make 

 

 

private void Window_Loaded(object sender, RoutedEventArgs e)

 

{

 

this.moduleManager.LoadModule("EmployeeModule");
.......


Peter

 

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.
Regards,
Julian
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
Peter