PRISM adding modules on demand

Topics: Prism v2 - WPF 4
Jun 28, 2010 at 10:31 AM

Hi, I have a set of tabs in my shell window and one main region whicxh is a contentcontrol. I also have four modules that I want to load on demand when a certain tab is selected. So when tab1 is selected I want to load moduleA, when tab2 is selected I want to load ModuleB, etc. The first module loads on when the application starts. The problem is that when I change the tab nothing happens. There are no errors tough. I'm using this version of prism Composite Application Guidance for WPF and Silverlight - October 2009.

I tried this approach:

Shell:

public partial class Shell : RibbonWindow, IShellView
   
{
       
private readonly IRegionManager regionManager;
       
private readonly IModuleManager moduleManager;

   
public Shell(IModuleManager moduleManager)
   
{
       
this.moduleManager = moduleManager;
       
InitializeComponent();

   
}

   
public void ShowView()
   
{
       
this.Show();
   
}



   
private void onTabSelection(object sender, RoutedEventArgs e)
       
{
                 
this.moduleManager.LoadModule("ModuleB");
       
}
}

Bootstrapper:

 public partial class MyBootstrapper : UnityBootstrapper
   
{
       
protected override IModuleCatalog GetModuleCatalog()
       
{
           
var catalog = new ModuleCatalog();
            catalog
.AddModule(typeof(ModuleA)).AddModule(typeof(ModuleB));

       
return catalog;
   
}

   
protected override void ConfigureContainer()
   
{
       
Container.RegisterType<IShellView, Shell>();

       
base.ConfigureContainer();
   
}



   
protected override DependencyObject CreateShell()
   
{
       
ShellPresenter presenter = Container.Resolve<ShellPresenter>();
       
IShellView view = presenter.View;

        view
.ShowView();

       
return view as DependencyObject;
   
}

}
And moduleB that I want to be able to load on demand (I used to use this commented line that's why I left it here):

[Module(ModuleName = "ModuleB", OnDemand = true)]
public class ModuleB : IModule
{  

   
private readonly IUnityContainer _container;
   
private readonly IRegionManager _regionManager;

   
public ModuleB(IUnityContainer container, IRegionManager regionManager)
   
{
        _container
= container;
        _regionManager
= regionManager;
   
}
   
public void Initialize() {

        _regionManager
.Regions["MainRegion"].Add(new ModuleBView());
       
this.RegisterViewsAndServices();

     
//  this._regionManager.RegisterViewWithRegion(RegionNames.MainRegion, () => _container.Resolve<MissionProfileView>());
   
}
   
protected void RegisterViewsAndServices()
   
{
        _container
.RegisterType<Modules.ModuleBView>();
   
}
}

What am I doing wrong here? How should I proceed?

Thanks for any help.
Jul 2, 2010 at 5:56 PM

Hi,

As this forum thread is closely related to this question you can follow it over there.

Fernando Antivero
http://blogs.southworks.net/fantivero