Module1 (Modular) Prism program frame

Prism framework with a new version, Prism7.1. Change on which the reference interest https://www.cnblogs.com/hicolin/p/8694892.html

How to tell Shell (our host program) which went Load Module, start at the beginning of the App, you need to create a configuration ModuleCatalog (used to manage Module).

Method 1: Create a directory module (ModuleCatalog) through the configuration file (App.config)

1, the new Prism Blank App (WPF) project: BlankApp7

Right at BlankApp7 mouse - add - new item - the application configuration file, App.config

2, the new Prism Module (WPF) project: ModuleA

3, ModuleA ModuleAModule.cs There is a file, and to achieve the associated ContentRegion the main form ViewA

using ModuleA.Views;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Regions;

namespace ModuleA
{
    public class ModuleAModule : IModule
    {
        public void OnInitialized(IContainerProvider containerProvider) 
        {
            var regionManager = containerProvider.Resolve<IRegionManager>();
            regionManager.RegisterViewWithRegion("ContentRegion", typeof(ViewA)); //viewA与ContentRegion进行关联
        }
        public void RegisterTypes(IContainerRegistry containerRegistry)
        {
            
        }
    }
}

App.xaml.cs directory is created in the configuration file

using BlankApp7.Views;
using Prism.Ioc;
using Prism.Modularity;
using System.Windows;

namespace BlankApp7
{
    public partial class App
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
        }
        protected override IModuleCatalog CreateModuleCatalog() 
        {
            return new new ConfigurationModuleCatalog (); // directory created in the configuration file 
        } 
    } 
}

Profile App.config, we have seen a ModuleAModule of Module named collection in ModuleA.dll in, whether startupLoaded loaded at startup (display).

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="modules" type="Prism.Modularity.ModulesConfigurationSection, Prism.Wpf" />
    </configSections>
    <modules>        
        <module assemblyFile="ModuleA.dll" moduleType="ModuleA.ModuleAModule, ModuleA" moduleName="ModuleAModule" startupLoaded="True" />
    </modules>
</configuration>

4, due BlankApp7 to load ModuleA, so to quote dll ModuleA generated.

Right at ModuleA mouse - generation, ModuleA bin folder will appear in ModuleA.dll

Right at BlankApp7 mouse - add - quote, browse, find ModuleA.dll (not recommended to copy and paste the dll to the bin directory BlankApp7, as if regenerated ModuleA.dll, then the new dll will not appear in the bin directory of BlankApp7, It is still a copy of the old dll)

The results are shown running

 

Guess you like

Origin www.cnblogs.com/xixixing/p/11488218.html