Oct 21, 2011 at 6:39 PM
Edited Oct 21, 2011 at 6:40 PM
Based on my understanding one way you could achieve this is to confirm that your module was initialized, to ensure your suscription is made before publishing the event. To do this you could define an
EventAgreggator wrapper class to obtain which modules were initialized and publish the event accordingly. You could compare the
ModuleCatalog.Modules collection and check if your required module was initialized. An example of this could be the following method:
public void IsModuleInitialized(string requiredModuleName)
return moduleCatalog.Modules.Where(e => e.State == ModuleState.Initialized).Where(e => e.ModuleName == requiredModuleName).FirstOrDefault() != null;
In case the module was initialized you could publish the event using the
EventAgreggator. If not, you could subscribe to the ModuleManager.LoadModuleCompleted event and then request to load your required module, so you can publish the event when the module ends loading.
While this approach will probably help you in your specific scenario, it would be worth noting that this implies a little bit of coupling between the modules in your application. As the documentation mentions,
"To keep the application and modules loosely coupled, the application should avoid using this event to integrate the module with the application..."
So, in my opinion you could try loading the module before publishing the event to avoid this situation.
I hope you find this useful.