How to activate a module after its initialize method has been executed?

I have one "MainRegion" (SingleActiveRegion) in my shell. My various modules will be loaded into this main region. I can populate a list of available modules in a menu (a module with MenuView.xaml) and select them to load. On the
click of the menu I do:

At the first time it all works OK, because the Initialize() methods of the modules are executed, but after Module1, Module2 and Module3 are initialized, nothing happens when I click to load Module2 again (Initialize() doesn't get executed anymore). I am
sure my code is wrong as I shouldn't be calling Initialize(), just to activate a module previously initialized, but moduleLoader doesn't give me any other options...

My question: how can I activate a module on demand, after its initialize method has been executed?

The Module Loader service only initializes the modules that weren’t initialized (has a collection of all the modules that have been already initialized in order to not initialize the same module
twice).

What you could do is have your on demand modules’ initializers subscribe to an event in the EventAggregator, but not show any view. Then your MenuView would initialize the module (which will really
be initialized only the first time), and later publish that same event in the event aggregator, passing the moduleName as an argument (there’s an overload in the subscription method that will let the module’s initializer filter and get only the events related
to itself).

This is when your module could reactivate (or add if it’s the first time) the views in the region.

private void MenuItem_Click(object sender, RoutedEventArgs e)

{

var module = moduleEnumerator.GetModule(moduleName);

moduleLoader.Initialize(new[] { module });

eventAggregator.GetEvent<ActivateModuleEvent>().Publish(moduleName);

}

I recommend you to avoid calling the
Initialize method more than one time. The purpose of it is to be called only once during the module's loading process, to perform module configuration and set up. The Composite Application Library provides several ways to implement loosely coupled communication
among different modules like: