Manually loading module using InitializeModules?...

Jun 18, 2013 at 9:37 PM
Hi,

I the source project of Prism Splash Screen Module and I want to convert this example of loading modules to Mef:
  public class Bootstrapper : UnityBootstrapper
  {
    protected override void ConfigureContainer()
    {
      Container.RegisterType<IShell, Shell>(new ContainerControlledLifetimeManager());
      base.ConfigureContainer();
    }

    protected override DependencyObject CreateShell()
    {
      var shell = Container.Resolve<IShell>();
      return shell as DependencyObject;
    }

    #region Private Properties
    private IEventAggregator EventAggregator
    {
      get { return Container.Resolve<IEventAggregator>(); }
    }
    #endregion

    protected override void InitializeModules()
    {
      IModule splashModule = Container.Resolve<Splash.Module>();
      splashModule.Initialize();

      EventAggregator.GetEvent<MessageUpdateEvent>().Publish(new MessageUpdateEvent {Message = "Module1"});
      Thread.Sleep(2000); //simulate long loading of the module
      IModule customersModule = Container.Resolve<Module1.Module>();
      customersModule.Initialize();

      EventAggregator.GetEvent<MessageUpdateEvent>().Publish(new MessageUpdateEvent { Message = "Module2" });
      Thread.Sleep(2000); //simulate long loading of the module
      IModule locationModule = Container.Resolve<Module2.Module>();
      locationModule.Initialize();

      EventAggregator.GetEvent<MessageUpdateEvent>().Publish(new MessageUpdateEvent { Message = "Module3" });
      Thread.Sleep(2000); //simulate long loading of the module
      IModule ordersModule = Container.Resolve<Module3.Module>();
      ordersModule.Initialize();
    }
  }
Having trouble coming up with a solution. I have large amounts of data to load and need this logic. I tried using the code from this project "Improving perceived WPF app startup performance with MEF and a Splash Screen", but also having trouble getting imports to work.

Help would really be appreciated, Thanks!
Jun 19, 2013 at 2:03 AM
I found my solution by using:
IModuleManager manager = ServiceLocator.Current.GetInstance<IModuleManager>();
manager.LoadModule("ModuleA");