(2) Analysis of the Main Ri Program

Source: Internet
Author: User

Download the source code of this article: myri_0.zip

After introducing the RI architecture in the previous article, we will use step by step to implement this system. Readers will follow me to complete it in five courses.

This article only builds a shell, including the main applicationProgramShell, public class library infrastructure, and four modules that do not have any function at the moment, the final effect is to load and run the four modules through shell.

This chapter does not seem to be difficult. First, add shell and stocktraderribootstrapper to the main application step by step. Pay attention to the module loading sequence in the getmodulecatalog method:

Marketmodule-> positionmodule-> watchmodule-> newsmodule

The mudule function is expanded in this order.

Next, add the four modules. Use the following format for dependency injection ):

Public classMarketmodule:Imodule{Private readonlyIregionviewregistryRegionviewregistry;PublicMarketmodule (IregionviewregistryRegistry ){This. Regionviewregistry = registry ;}# RegionImodule membersPublic voidInitialize () {regionviewregistry. registerviewwithregion ("Marketregion",Typeof(Views.Marketview));}# Endregion}

Create a view accordingly. Currently, no logic is required.

At the same time, four region IDs are defined in shell. XAML of the main program. For details, refer:

These region definitions are defined in the regionnames enumeration of the public class library infrastructure. We have mentioned before:

Public static classRegionnames{Public const stringMaintoolbarregion ="Maintoolbarregion";Public const stringMainregion ="Mainregion";Public const stringOrdersregion ="Ordersregion";Public const stringSecondaryregion ="Secondaryregion";Public const stringActionregion ="Actionregion";Public const stringResearchregion ="Researchregion";}

The first stage is as follows:

Isn't it enjoyable? Therefore, we also use the MVP mode in shell. The procedure is as follows:

1) Create an ishellview, expose the showview method, and use the shell view to implement this interface:

Public interfaceIshellview{VoidShowview ();}
Public partial classShell:Window,Ishellview{PublicShell () {initializecomponent ();}# RegionIshellview membersPublic voidShowview (){This. Show ();}# Endregion}

2) create shellpresenter

Public classShellpresenter{PublicShellpresenter (IshellviewView) {view = view ;}PublicIshellviewView {Get;Private set;}}

3) override the configurecontainer method of stocktraderribootstrapper and register the ishing between ishellview and shell:

Protected override voidConfigurecontainer () {container. registertype <Ishellview,Shell> ();Base. Configurecontainer ();}

4) rewrite the createshell method of the stocktraderribootstrapper method:

Protected overrideDependencyobjectCreateshell (){ShellpresenterPresenter = container. Resolve <Shellpresenter> ();IshellviewView = presenter. view; view. showview ();ReturnViewAsDependencyobject;}

We found that the presenter-first method is used here -- create presenter first and then create view. The above four steps are the standard process for creating an MVP mode (in this example, there is no model, even the VP mode at best ). In the following sections, we will see many variants such as view-first and VM.

In the main program, iloggerfacade is implemented to record logs, that is, the enterpriselibraryloggeradapter class. Currently, this class is unavailable. We will see how it works later.

 

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.