Asp. Net development architecture design (1)

Source: Internet
Author: User

 

In the past few days, discussions about software architecture have been intense. Everyone wants an architecture that minimizes dependencies between layers to adapt to changing needs, no one would like to change the whole body and try to reduce the mutual impact of changes at each layer.

 

In this article, I will discuss my solution from two aspects: Theory and Practice (Source Code). I hope you will give more valuable comments.

I. Concept of software architecture. What is software architecture? My understanding is: the software architecture includes two aspects: one is the software development architecture, the other is the software deployment architecture, and the so-called deployment architecture refers to the distributed deployment at the time of deployment, cluster and other design issues; development architecture is what we usually talk about in software hierarchy design, that is, what we want to talk about today.

2. What is hierarchy? How many layers are there? Layering means dividing a large software solution into multiple projects for development. There are three types of solutions. One is stratified by the Code functional level, which is divided into the database access layer and the business logic layer, UI Layer. One is to layer according to the functional modules to be implemented, such as the news management layer and blog management layer. The third is to combine the first two to layer: the layers are divided according to the code functions, and then divided into functional modules in each layer.

3. Can Interface-oriented interfaces reduce the dependency between layers? What else do I need? The interface-oriented interface only transfers the direct call to the interface, but the interface call also requires the Object Instantiation as the premise, because the Object Instantiation exists, therefore, the interface cannot block the objects behind it to complete the function. In this case, the concept of dependency injection/control inversion emerged, and the IOC container emerged, which allows the object to be automatically instantiated, and manage the living space of objects.

4. What should I do if I say so much? We may wish to consider from the software development process that we all know that we need to conduct requirement analysis and need to have requirement analysis documents, the task of requirement analysis is to transform the customer's requirements into the requirements for software functions. The main content includes: What business operations are included in each functional module of the software to implement those functional modules, what pages (or Windows) are required for these business operations? What are these pages like and what are there above? With this information, we can start our system design.

The reference relationships between projects in my solution are as follows:

Note:

Web: UI Layer, Asp.net Web Application Project, provides a user interface.

UnityConfig: dependency injection configuration layer, Class Library Project, and Service layer and Business layer are configured to provide to the Web call Service layer.

Service: provides services for the Web layer, class library projects, which are full of interfaces.

Business: Business logic layer. It calls the DA data access layer and Entities layer to implement Service interface at the Service layer. Class Library Project.

Entities: entity layer, Class Library Project, Business Entity storage, anemia entity.

Note: In the above reference relationship, the Web layer does not directly reference the Business layer.

Now let's assume that we have a requirement document: It only needs to implement a function module, that is, to find and display the employee list. Page form

 

 

First, we design the service as needed. Because there is only one function module, we only need one interface class, and because there is only one operation function (search ), therefore, we only need one Service method, so we create an interface class in the Service layer: IQueryEmployeeService, and add an interface method: QueryEmployee.

As shown on the page, our service method requires two object parameters, one is the search condition and the other is the search result. In this way, we get two object classes. In Entities, the names are QueryEntry and ListEntry.

The Code is as follows:

Namespace Xiaozhuang. Service

{

Public interface IQueryEmployeeService

{

/// <Summary>

/// Query employee information

/// </Summary>

/// <Param name = "queryentity"> </param>

/// <Returns> </returns>

List <listentry> queryemployee (queryentry );

}

}

Namespace xiaozhuang. Entities

{

Public class queryentry

{

Public String inclumentid {Get; set ;}

Public String employeename {Get; set ;}

Public String employeeage {Get; set ;}

Public override string tostring ()

{

Return "deaprtmentid:" + inclumentid + "employeename:" + employeename + "employeeage:" + employeeage;

}

}

}

Namespace xiaozhuang. Entities

{

Public class listentry

{

Public String employeeid {Get; set ;}

Public String employeename {Get; set ;}

Public string EmployeeSex {get; set ;}

Public int EmployeeAge {get; set ;}

Public string DepartmentName {get; set ;}

Public string MobilePhone {get; set ;}

Public override string ToString ()

{

Return "EmployeeID:" + EmployeeID + "EmployeeName:" + EmployeeName + "EmployeeSex:" + EmployeeSex;

}

}

}

Please note that the design of the business entity comes from the reference page, and the design of the object field type also comes from the reference page, most of which are of the String type, this is because you do not know how to store the data in the database.

Of course, in the actual project, because the Department list also requires the establishment of the Department's business entity, here is a simple process, with these business entities and service interfaces, we can design the database, after the database design is complete, the system design is complete.

The next step is to implement this search method in the Business layer:

Namespace Xiaozhuang. Business

{

Public class QueryEmployeeBusiness: IQueryEmployeeService

{

# Region IQueryEmployeeService Member

 

Public List <ListEntry> QueryEmployee (QueryEntry queryentry)

{

List <ListEntry> listEntry = new List <ListEntry> ();

ListEntry entry1 = new ListEntry () {EmployeeID = "1", EmployeeName = "Employee 1", EmployeeSex = "male", DepartmentName = "department 1", EmployeeAge = 30, mobilePhone = "123546789 "};

ListEntry entry2 = new ListEntry () {EmployeeID = "2", EmployeeName = "EMPLOYEE 2", EmployeeSex = "female", DepartmentName = "Department 2", EmployeeAge = 29, mobilePhone = "123546789 "};

ListEntry. Add (entry1 );

ListEntry. Add (entry2 );

Return listEntry;

}

 

# Endregion

}

}

The method for querying databases is omitted here. You can use the LINQ to SQL implementation or other ORM tools.

Next, configure our unityconfig layer to access this employee's service on the web layer.

Namespace xiaozhuang. unityconfig

{

Public interface icontaineraccessor

{

Iunitycontainer container {Get ;}

}

 

Public class unitycontainerconfig

{

Public iunitycontainer getiunitycontainer ()

{

IUnityContainer container = new UnityContainer ();

Container. RegisterType <IQueryEmployeeService, QueryEmployeeBusiness> ();

Return container;

}

 

}

}

Of course, you can also write this configuration to the Web. Config.

The next question is how to call this service on the Web layer. The question is actually complicated. The article is too long for everyone to read, I will discuss this issue in detail next time.


 

 

 

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.