是否可以仅在加载所有模块后才显示外壳? [英] Is it possible to show a shell only once all the modules have been loaded?

查看:51
本文介绍了是否可以仅在加载所有模块后才显示外壳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个应用程序,该应用程序使用 PRISM 4 将其功能划分到不同的模块中.

I'm currently working on an application which uses PRISM 4 to divide its functionalities in different modules.

我注意到我的应用程序的 Shell(在其区域中保存模块的视图)在模块加载之前被加载和显示.

I noticed that my application's Shell, which holds the modules' views in its regions, is loaded and displayed before the modules are loaded.

这意味着首先显示 Shell,然后在相当长的一段时间内(大约半秒),加载模块并将视图插入到 Shell 的区域中.这很烦人,因为用户在启动时会看到一个空壳,这不是很专业.

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 into the Shell's regions. It's rather annoying, as the user is greeted with an empty shell at start-up, which isn't very professional.

有没有办法检测所有模块何时加载?我可以在引导程序中覆盖的任何方法?

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

如果可以,我想隐藏 Shell(或显示加载装饰器),直到所有模块都加载完毕.

If I could, I would like to hide the Shell (or display a loading adorner) until all the modules have been loaded.

推荐答案

我找到了一个相对简单的解决方案.

I found a relatively simple solution.

我的应用程序有一个名为 ShellHandler 的类,它在引导程序中实例化并在 Unity 容器中注册为单例:

My application has a class named ShellHandler, which is instanciated in the bootstrapper and registered in the Unity Container as a singleton:

Container.RegisterType<IShellHandler, ShellHandler>(new ContainerControlledLifetimeManager());

我在我的 ShellHandler 中创建了一个方法,模块可以使用该方法将自己标记为已加载:

I created in my ShellHandler a method which can be used by modules to flag themselves as loaded:

 /// <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 类中,我创建了一个在初始化过程中调用的抽象方法:

Finally, in my ModuleBase class, which all modules implement, I created an abstract method which is called during the initialization 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 单例的实例:

Each module now resolves the instance of the ShellHandler singleton through their constructor:

 public LoginModule(IUnityContainer container, IRegionManager regionManager, IShellHandler shellHandler) 
        : base(container, regionManager)
 {
      this.ShellHandler = shellHandler;
 }

最后他们实现了 ModuleBase 的 Abstract 方法:

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

这篇关于是否可以仅在加载所有模块后才显示外壳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆