Я нашел относительно простое решение.
В моем приложении есть класс с именем ShellHandler, который создается в загрузчике и регистрируется в контейнере Unity как синглтон:
Container.RegisterType<IShellHandler, ShellHandler>(new ContainerControlledLifetimeManager());
Iсоздал в моем ShellHandler метод, который может использоваться модулями для пометки себя как загруженного:
/// <summary>
/// Method used to increment the number of modules loaded.
/// Once the number of modules loaded equals the number of modules registered in the catalog,
/// the shell displays the Login shell.
/// This prevents the scenario where the Shell is displayed at start-up with empty regions,
/// and then the regions are populated as the modules are loaded.
/// </summary>
public void FlagModuleAsLoaded()
{
NumberOfLoadedModules++;
if (NumberOfLoadedModules != ModuleCatalog.Modules.Count())
return;
// Display the Login shell.
DisplayShell(typeof(LoginShell), true);
}
Наконец, в моем классе ModuleBase, который реализуют все модули, я создал абстрактный метод, который вызывается во время инициализацииprocess:
/// <summary>
/// Method automatically called and used to register the module's 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();
Каждый модуль теперь разрешает экземпляр синглтона ShellHandler через своего конструктора:
public LoginModule(IUnityContainer container, IRegionManager regionManager, IShellHandler shellHandler)
: base(container, regionManager)
{
this.ShellHandler = shellHandler;
}
И, наконец, они реализуют метод Abstract из 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();
}