[.net development framework] .NETC # three-layer development structure Demo detailed explanation and source code (1)

The year is approaching, and things are much less. Although I have been exposed to some three-layer structure projects, I have never written them carefully from beginning to end. Many things are still vague. This time I spent a few days writing from beginning to end. Such a small Demo came out, and the process is recorded here, for me to review more conveniently in the future, and hope to help some friends.

The project is divided into Model, IDAL, IBLL, DAL, BLL, WebUI, the database is SQLServer, the data access uses EntityFramework5.0, uses a simple factory, singleton, abstract factory, and uses the reflection + configuration file to load the class library. Change compile time to run time.

benefit:

1. Can be developed in parallel to improve development efficiency;

2. The database is not limited, and the database can be replaced at low cost;

3. Code reuse, a data access layer can be used for multiple business logic layers, and a business logic layer can supply data to multiple expressions;

4. Coupling is reduced, modules are less dependent on each other, pluggable modules are easy to maintain, easy to update, and BUG positioning is more accurate;

5. It should be there, I can't think of it ...

The source code has been published to Code Cloud: https://gitee.com/xianglikai1/CSharpSanCengKaiFaDemo

Three-tier structure: data access layer, business logic layer, presentation layer, and the project structure is as follows:

Model: data entity model

IDAL: data access interface description

IBLL: business logic interface description

TestDAL: Implementation library of data access interface

TestBLL: Implementation logic library of business logic interface

WebUI: Web presentation layer

The database uses two tables, Users and Nation, the structure is as follows:

Model layer, using EntityFramework5.0, added an extension class file

ExtendModel.cs code

IDAL data access interface description, such libraries need to refer to Model, including a basic interface, two entity class operation interfaces, and a factory;

IBaseIDAL.cs basic interface code

IUsersIDAL.cs and INationIDAL.cs entity class operation interface code

DALFactory.cs factory class code, using reflection and configuration file loading to achieve class libraries and objects, while reducing the difficulty of external use

TestDAL data access interface implementation, need to reference Model and IDAL, but it is dynamically loaded

DbContextFactory.cs data context singleton factory code

BaseDAL.cs data access basic interface implementation class, without having to implement repeated methods in each specific data access class

The specific implementation code of UsersDAL.cs and NationDAL.cs

At present, the three parts of Model, IDAL and DAL are completed, the process is

The role of IDAL is to understand the coupling. IDAL provides the model data access operation interface description. DAL implements IDAL. The factory in IDAL loads DAL through the runtime mode, and simplifies the degree of external use, realizes parallel development, and will be replaced The work of the database is reduced to a minimum, reducing the BUG rate.

The next article will write IBLL, BLL, WebUI.

Guess you like

Origin www.cnblogs.com/likesoft/p/12722408.html