Is it possible to show the shell only after all the modules have been loaded?

I am currently working on an application that uses PRISM 4 to separate its functions in different modules.

I noticed that my Shell application, which stores module views in its regions, loads and displays before loading the modules.

This means that the shell is displayed first, and a considerable amount of time later (about half a second), the modules are loaded and the views inserted in the shell area. This is rather annoying, as the user welcomes the empty shell at startup, which is not very professional.

Is there any way to detect when all modules have been loaded? Any method I can override in the bootloader?

If I could, I would like to hide the shell (or show the advertiser downloads) until all modules are loaded.

+6
source share
2 answers

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:

  /// <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); } 

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(); } 
+3
source

You can show the shell view after initializing the modules:

 protected override void InitializeShell() { Application.Current.MainWindow = (Window)Container.Resolve<ShellView>(); } protected override void InitializeModules() { base.InitializeModules(); Application.Current.MainWindow.Show(); } 
+7
source

Source: https://habr.com/ru/post/898285/


All Articles