I found a relatively simple solution.
In my application, there is a class called ShellHandler, which is initialized in the loader and registered in the Unity container as a singleton:
Container.RegisterType<IShellHandler, ShellHandler>(new ContainerControlledLifetimeManager());
I created a method in my ShellHandler that can be used by modules to load themselves as downloadable ones:
Finally, in my ModuleBase module, which all modules implement, I created an abstract method that is called during the initialization process:
/// <summary> /// Method automatically called and used to register the module views, types, /// as well as initialize the module itself. /// </summary> public void Initialize() { // Views and types must be registered first. RegisterViewsAndTypes(); // Now initialize the module. InitializeModule(); // Flag the module as loaded. FlagModuleAsLoaded(); } public abstract void FlagModuleAsLoaded();
Each module now resolves a Singleton ShellHandler instance through its constructor:
public LoginModule(IUnityContainer container, IRegionManager regionManager, IShellHandler shellHandler) : base(container, regionManager) { this.ShellHandler = shellHandler; }
And finally, they implement the abstract method from ModuleBase:
/// <summary> /// Method used to alert the Shell Handler that a new module has been loaded. /// Used by the Shell Handler to determine when all modules have been loaded /// and the Login shell can be displayed. /// </summary> public override void FlagModuleAsLoaded() { ShellHandler.FlagModuleAsLoaded(); }
source share