Prism 5.0 source code for reading ModuleCatalog, graphpadprism5.0

Source: Internet
Author: User

Prism 5.0 source code for reading ModuleCatalog, graphpadprism5.0

Concept

ModuleCatalog is one of the main concepts in Prism. It is mainly used to save the available modules of an application. Every module is defined by ModuleInfo (including the module name, type, and location ).

Function implementation

ModuleCatalog inherits from IModuleCatalog. IModuleCatalog declares the following attributes and methods:

  • All modules saved by ModuleCatalog
    IEnumerable<ModuleInfo> Modules { get; }
  • Obtains the modules that a module depends on.
    IEnumerable<ModuleInfo> GetDependentModules(ModuleInfo moduleInfo);  
  • Obtain all the modules that contain the modules parameter and its dependencies.
    IEnumerable<ModuleInfo> CompleteListWithDependencies(IEnumerable<ModuleInfo> modules);  
  • Initialize ModuleCatalog. you can load modules and verify modules in this method.
    void Initialize();
  • Add a module to ModuleCatalog
     void AddModule(ModuleInfo moduleInfo);

In addition to implementing the attributes and Methods declared by IModuleCatalog, ModuleCatalog provides many other attributes and methods:

  • Grouped modules and non-grouped modules are defined.
            public IEnumerable<ModuleInfoGroup> Groups        {            get            {                return this.Items.OfType<ModuleInfoGroup>();            }        }        protected IEnumerable<ModuleInfo> GrouplessModules        {            get            {                return this.Items.OfType<ModuleInfo>();            }        }
  • Modules: Get all modules, including grouped and non-grouped
            public virtual IEnumerable<ModuleInfo> Modules        {            get            {                return this.GrouplessModules.Union(this.Groups.SelectMany(g => g));            }        }
  • Provides two static methods for creating ModuleCatalog from XAML.
    public static ModuleCatalog CreateFromXaml(Stream xamlStream)public static ModuleCatalog CreateFromXaml(Uri builderResourceUri)
  • Verify modules:
  • Several AddModule methods are overloaded.
  • Provides the method for adding a Module Group.
     public virtual ModuleCatalog AddGroup(InitializationMode initializationMode, string refValue, params ModuleInfo[] moduleInfos)

ModuleCatalog can also be used as a base class to customize catalog.

Application

There are two Module Catalog related methods in Bootstrapper: Create and configure.

        protected virtual IModuleCatalog CreateModuleCatalog()        {            return new ModuleCatalog();        }        protected virtual void ConfigureModuleCatalog()        {        }

When Using Prism to build a WPF application, we generally customize a bootstrapper that inherits the prism UnityBootstrapper or MefBootstrapper (of course, you can also use extension bootstrapper of other IoC container ).

In the defined bootstrapper, You need to override the ConfigureModuleCatalog method and add the specific module to the module catalog.

        protected override void ConfigureModuleCatalog()        {            base.ConfigureModuleCatalog();            ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog;            moduleCatalog.AddModule(typeof(HelloWorldModule.HelloWorldModule));        }

Summary

The overall implementation of ModuleCatalog is relatively simple and easy to understand. However, there is a very important algorithm mentioned in this article. I will write an article to introduce it separately.

This algorithm is used to verify the circular reference between modules.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.