tags:

views:

322

answers:

1

Can anyone explain the difference between this way of loading modules in Prism:

protected override void InitializeModules()
{
    IModule customerModule = Container.Resolve<CustomerModule.CustomerModule>();
    IModule helloWorldModule = Container.Resolve<HelloWorldModule.HelloWorldModule>();

    customerModule.Initialize();
    helloWorldModule.Initialize();
}

and this way:

protected override IModuleCatalog GetModuleCatalog()
{
    ModuleCatalog catalog = new ModuleCatalog()
        .AddModule(typeof(CustomerModule.CustomerModule))
        .AddModule(typeof(HelloWorldModule.HelloWorldModule));
    return catalog;
}

I've seen both ways in demos but as far as I can tell they do the same thing, both seem to pass in a container and regionManager that I need in my modules:

public class CustomerModule : IModule
{
    public IUnityContainer Container { get; set; }
    public IRegionManager RegionManager { get; set; }

    public CustomerModule(IUnityContainer container, IRegionManager regionManager)
    {
        Container = container;
        RegionManager = regionManager;
    }

    public void Initialize()
    {
        RegionManager.RegisterViewWithRegion("MainRegion", typeof(Views.CustomerView));
    }

}
+2  A: 

Both IModuleCatalog GetModuleCatalog() and InitializeModules are from UnityBootstrapper.

  • GetModuleCatalog is for configuring how you want to load the module. And InitializeModules is for initializing the module.

  • GetModulecatalog will be fired before calling Initializing the module.

  • You don't need to override the InitializeModules for the most of scenarios but you will need to tell the UnityBootstrapper how you want your modules to be loaded (based on app.config, Directory Lookup or Xap Dynamic Loader or etc)

Hope it helps.

Michael Sync