当前位置:网站首页>Introduction to prism framework - Modular introduction

Introduction to prism framework - Modular introduction

2022-06-12 01:30:00 Tsim Sha Tsui Duan Kun 415

  In actual work, we will divide the functions into multiple modules for development

- Onion structure —— Separation is for better union

In order to make the software easy to maintain , test , And flexible enough , So there is the onion structure , It is a good choice to develop any software

Code dependencies are from the outside in , The code in the inner ring should not know anything about the outer ring .

The outer layer depends on the inner layer , The inner layer has no perception of the outer layer

2008 year Jeffrey Palermo Proposed onion architecture

Key principles of onion Architecture :

  • Build applications around independent object models
  • The inner layer defines the interface , The outer layer implements the interface
  • The direction of dependence points to the center of the circle
  • All application code can be compiled and run independently of the infrastructure

—— Jeffrey Palermo 2008, The Onion Architecture: part 3


 

 prism Examples of modular functions

Create two new projects , Then attribute - change WPF The application is a class library
 

Add... To the two class libraries respectively Views Folder - Then add a paragraph of text to show

viewa and viewb 

A program is recognized as a module because it has certain characteristics

Then create a new class ModuleAProfile

And then manage nuget Add... To the package Prism.Dryloc My bag

Turn it out and implement it in the class IModule This interface

( Then we realized that we can not implement this method , Then delete the method )

public class MouleAProfile : IModule
    {
        public void OnInitialized(IContainerProvider containerProvider)
        {
           
        }

        public void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterForNavigation<viewA>();// Register here ViewA, Remember to add views Declaration space for 
        }
    }

  And then the same thing ,ModuleB It's the same operation

Add... To the solution ModuleA and ModuleB Project references for

  Then add the method

protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
            {
                moduleCatalog.AddModule<ModuleAProfile>();
                moduleCatalog.AddModule<ModuleBProfile>();
                base.ConfigureModuleCatalog(moduleCatalog);
            }

You can achieve cross region search

But this is a strong reference method , There's another way

First, remove the strong reference to , Then delete the calling and reference projects  

find ModuleA and ModuleB Of bin/Debug Inside dll Suffix program

Create a new folder in the same location as the folder in the main application , It contains the required assemblies

Then set the folder name

Used to find

 public class Xin
    {
        public partial class App : PrismApplication
        {
            protected override Window CreateShell()
            {
                return Container.Resolve<Mainview>();
            }
            protected override void RegisterTypes(IContainerRegistry containerRegistry)
            { 

            }
            protected override IModuleCatalog CreateModuleCatalog()
            {// You can directly return the specified module address   In this way, the coupling relationship is greatly reduced 
                return new DirectoryModuleCatalog() { ModulePath = @".\Modules" };
            }

        }
    }

 return new DirectoryModuleCatalog() { ModulePath = @".\Modules" };

When this method is started, it will be loaded when it meets the contract

7-Modules-AppConfig

7-Modules-LoadManual
7-Modules-Xaml

Are used to load modular

Github Of prism Module call cases

The general method is : Set up a way to find modularity - Then define a required module - Hit a corresponding container - After startup, the automatic matching search is loaded


 

原网站

版权声明
本文为[Tsim Sha Tsui Duan Kun 415]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206120124209132.html