DotNET Enterprise Architecture Application practices-business hierarchy in instance architecture design-extract independent business Layers

Source: Internet
Author: User
Tags idn

The original idea is to teach you how to use AgileEAS step by step. NET base library for application development-articles related to the series of directories to gradually explain Based on AgileEAS. NET platform for application development, but in the case of the process, we have to talk about AgileEAS. in terms of Architecture Design for application development on the NET platform, I will separate some articles related to the architecture. I am based on AgileEAS.. NET platform application development examples to explain the architecture design, so this article should have a subtitle "Step by Step teach you to use AgileEAS. NET basic library for application development-basic articles-extract independent business layer ", if possible, I will base on these independently extracted articles, here is an example of a series of DotNET Enterprise Architecture Application practices.

 

Series Review

In the previous article, I started to talk about Unified Data Access. Through UDA TO THE ORM step by step, we talked about the data access layer in the application system development architecture, the interface-driven data layer is described in detail. NET basic library for application development-basics-interface-driven data layer I mentioned the following layered model:

 

However, strictly speaking, we have been talking about the data access layer. In the demo, we have completed an independent business logic layer. The overall structure is as follows:

About Business Layer

The Business Logic Layer (BLL or BL) is the Business Logic Layer that implements application Business Logic processing. From the theoretical point of view of the system architecture, business logic processing exists in any architecture system. We extract the code that processes the business logic independently to form an independent business layer.

So what is the business layer doing? In the database-based management information system, most of them adopt a benchmark layered architecture such as UI> BL --> DAL or an extension based on this benchmark architecture, for example, the UI --> BL-Agent-> BL-> DAL or UI --> BL-Agent-> SL-> BL-> DAL structure.

In a hierarchical system such as UI --> BL --> DAL, the business layer uses the data access service provided by the DAL layer to encapsulate the business logic for use by the UI Layer, that is, the business layer converts the business processing required by the UI and processes the services provided by the DAL layer according to the business process.

 

 

Current problems

Now let's go home and see the example we demonstrated above. In our example, we only break down the UI (ClassLib. ormDemo) and DAL layer (ClassLibDemo. DAL. interface, ClassLibDemo. DAL. SQLServer), is there no business logic? This is not, but the business logic is broken down into the DAL and UI layers, because the data objects in the DAL layer already provide CRUD for Data Service Processing by default, it is also a kind of business processing and complicated business, for services such as product warehouse receiving, we write them by the programmer and add them to the segment classes in the generated DAL code.

Of course, this process is an option for a very simple application. If this application is very complicated, we will adopt this structure to make the code structure a little messy, we need to propose an independent business logic layer (BL ).

Structure Change

Now we need to add a project ClassLibDemo. BL to the original dismissal scheme, and the project structure is changed to the following:

 

 

 

In ClassLib. ormDemo and ClassLibDemo. DAL. add a project ClassLibDemo to the Interface. BL is responsible for completing services other than ORM object CRUD. We can also see ClassLib. ormDemo also has ClassLibDemo. BL for ClassLibDemo. DAL. interface.

There is a debate on this issue, that is, whether the ORM object should be an independent storage object or have certain business functions, such as Insert, Update, and Delete. We will not discuss this, in the current AgileEAS.. NET platform, the ORM object contains these business logic functions.

For the above reasons, in application development based on the AgileEAS. NET platform, the business layer is responsible for processing services other than the ORM object CRUD, that is, complex business logic.

Change code

Now I will demonstrate the changes to the product warehouse receiving business. First, we can comment out or delete the ClassLibDemo. DAL. in the Interface project, the IProductInList method ProductIn is defined and the ClassLibDemo is deleted. DAL. SQL Server-related code, in ClassLibDemo. add a class ProductInBL in BL. The Code is as follows:

 

1 public class ProductInBL: EAS. Business. BusinessObject
2 {
3 /// <summary>
4 // product warehouse receiving service.
5 /// </summary>
6 /// <param name = "pInList"> </param>
7 public void ProductIn (IProductInList pInList)
8 {
9 this. DataAccessor. TransactionExecute (new TransactionHandler2 (this. InternalIn), pInList );
10}
11
12 void InternalIn (IDataAccessor accessor, params object [] parameters)
13 {
14 IProductStore pStore = DALHelper. DALManager. CreateProductStore ();
15 pStore. DataAccessor = accessor;
16
17 IProductInList pInList = parameters [0] as IProductInList; // set the parameter value.
18
19 foreach (IProductIn pIn in pInList. Rows)
20 {
21 pIn. DataAccessor = accessor;
22 pIn. Idn = pIn. GetMaxNewIdn ();
23 pIn. Insert ();
24
25 pStore. Code = pIn. Code;
26 pStore. Price = pIn. Price;
27 pStore. Refresh ();
28
29 if (pStore. Exists)
30 {
31 pStore. Number + = pIn. Number;
32 pStore. Update ();
33}
34 else
35 {
36 pStore. Idn = pStore. GetMaxNewIdn ();
37 pStore. Code = pIn. Code;
38 pStore. Name = pIn. Name;
39 pStore. Spec = pIn. Spec;
40 pStore. Unit = pIn. Unit;
41 pStore. Price = pIn. Price;
42 pStore. Number = pIn. Number;
43 pStore. Insert ();
44}
45}
46}
47}

 

We modified the code ProductInDemo for calling the warehouse receiving service in the UI project as follows:

 

1 class ProductInDemo
2 {
3 public void ProductIn1 ()
4 {
5 this. ProductIn2 ();
6}
7
8 public void ProductIn2 ()
9 {
10 IProductInList pInList = DALHelper. DALManager. CreateProductInList ();
11
12 IProduct dict = DALHelper. DALManager. CreateProduct ();
13 dict. Code = "1AZ0002094 ";
14 dict. Refresh ();
15
16 IProductIn pIn = DALHelper. DALManager. CreateProductIn ();
17 pIn. Code = dict. Code;
18 pIn. Name = dict. Name;
19 pIn. Spec = dict. Spec;
20 pIn. Unit = dict. Unit;
21 pIn. Price = 12.8 M;
22 pIn. Number = 200;
23
24 pIn. InTime = DateTime. Now;
25 pIn. BillCode = DateTime. Now. ToString ("yyyyMMddHHmmss") + "_ 1 ";
26 pIn. Operator = "james-orm ";
27 pInList. Rows. Add (pIn );
28
29 try
30 {
31 new ProductInBL (). ProductIn (pInList );
32 System. Console. WriteLine ("warehouse receiving is completed. ");
33}
34 catch
35 {
36 System. Console. WriteLine ("warehouse receiving is not completed. ");
37}
38}
39}

 

Finally, compile and run:

For the structure of the data table involved in this example, refer to the data table structure based on AgileEAS. NET platform basic library for application development-General description and data definition, for data object model definition files, documents, DDL scripts download: Workshop.

 

Link

Step by step teach you how to use the AgileEAS. NET base class library for application development-series directory

AgileEAS. NET platform development guide-series Directories

Introduction to AgileEAS. NET application development platform-Index

AgileEAS. NET platform application development tutorial-case plan

Official website of AgileEAS. NET

Agile Software Engineering Lab

QQ: 116773358

 

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.