The actual unveiled: development .NET platform application system framework

xiaoxiao2021-03-06  57

Microsoft's .NET platform provides a very good basic system platform for application development, how is it to build your own application on this system platform, and we need to build your own application framework for the characteristics of the application system (Framework ). In the process of applying the .NET development system, we combined with many years of development experience, also referring to J2EE architecture, designed a set of application system frameworks under .NET, and corresponding middleware and development tools, already in multiple projects. Application in neutralizing software products has achieved good results. Now introduce the overall solution for this framework, I hope to help you.

We know that for a typical three-layer application, the system can usually divide the system into the following three levels:

· Database layer

· User interface layer

· Application Service Layer

For the application system, in these three levels, the system's main function and business logic are processed in the application service layer. For the system framework, the main processing is also the architecture of this level.

For the application service layer, in an object-oriented system, the following aspects of the following aspects must be processed:

· Data representation, that is, the representation of the entity class, and the corresponding relationship with the database, that is, the so-called O-R Map problem.

· The data is accessible, that is, the persistence problem of the entity class, usually using the database to permanently store the data entity, which requires solving the interaction problem with the database. This part is to complete, that is to save the data entity into the database, or read data entities from the database. The same is related to this part is the use of data access objects. In the frame, we have made a layer of encapsulation in ADO.NET, making it easier, and also unifying the use of ADO.NET.

· Organization of business logic. In an object-oriented system, business logic is implemented by messaging between objects. In this section, in order to ensure the correctness and reliability of logic processing, it is necessary to support transaction processing.

· Provide way of business services. In order to ensure the flexibility and encapsulation of the system, the system must have a layer to encapsulate these business logic, serve the client, while as an interface between the functional calls between the system, to ensure high-polymerization and low coupling of the system. The customer refers to the user refers to the user who is called, but the interface, other programs, etc. The web layer (ASP.NET page) is usually only interacting with this part, not the functionality of the business logic layer or data entity.

In order to solve these problems very well, we designed this framework. In the framework, for the above problems, we divide the application service layer into five levels: data entity layer, entity control layer, data access layer, business rules layer, and business appearance layer. The relationship between each level can be expressed as follows:

Hierarchical problem data entity layer data representation of physical control layer data access layer provides access to database access, encapsulation ADO.NET business rule layer business logic's Organizational business appearance layer business service

The system is divided into so many layers, and the advantage is that the system's architecture is more clear, so that each level is completed, the function is compared, and the code is ruled by law, which means we can develop some tools to generate these. Code, thereby reducing the workload of code written, enabling developers to put more energy on the processing of business logic. It is based on this idea, we have developed development tools for this framework, and reduce the number of code in actual work, and the effect is very good. At the same time, in order to apply the service layer better, we have designed an application system middleware that supports this framework. (Now, many other companies have tried this middleware system.) Different from the EntityBean of J2EE, we have adopted data entities and entities to control separate design methods, which will bring a certain benefit.

Below I will introduce the design and strategies of each part as follows:

Data entity layer

We first need to solve the problem of data representation, that is, the usual O-R Map problem.

O-R MAP usual approach is to map classes in the program to one or more tables of the database, such as a simple product class:

Public Class ProductId; String ProductName; Float Account;

A PRODUCT table may be corresponding in the database:

Field Name Data Type ProductID VARCHAR (40) ProductName Varchar (50) Account Float

This is the most common practice, but this way will bring some problems. The first is that the data entity is different in the database and program. For some "coarse granular objects" involved in multiple tables, one entity class may reference multiple other entity classes, which means that the object is involved. There are some problems in the modeling of granularity; followed by interacting with the database, there is also a conversion problem, if an object involves the operation of multiple tables, the problem is greater; finally, when the system is inquiry, When multiple objects need to be returned, because the problem involves conversion, the efficiency is relatively low, and if it is used to return to the data set, although the efficiency, the problem is inconsistent with the inconsistency.

Considering the above problems, we use another way in the performance of the data entity, which is to use the DataSet. DataSet is Microsoft's new data object in ADO.NET, which is different from ADO's Recordset, which can accommodate multiple records. DataSet is similar to a memory database consisting of multiple DataTable, while a DataTable has multiple column. Such a structure allows him to map with a database. At the same time, we have learned the advantages of CMP in the J2EE architecture to define the entity class structure in the J2EE architecture, using similar solutions.

Therefore, in this respect, we are processed:

1) The core class library defines the EntityData class. This class has inherited the DataSet, adding some methods to use the frame classes of all entity classes to define the general structure of each entity class, as for each entity class specific structure, The runtime is determined by the following measures:

2) The definition of the entity class is determined by the XML file, which conforms to the JIXML object entity description language specification (Note: Jixml is the object-entity mapping language we developed) to determine the structure of the entity class.

For example, a definition of an entity class with an order may be similar to the following structure: Product Product ProductType ProductTypeID ProductTypeID

INSERT INTO Product (ProductID, ProductName, ProductTypeID, CurrentCount, UnitName) VALUES (@ProductID, @ProductName, @ProductTypeID, @CurrentCount, @UnitName) < / Param> UPDATE Product SET ProductName = @ ProductName, ProductTypeID = @ProductTypeID, currentCount = @ currentCount, UnitName = @ UnitName WHERE ProductID = @ ProductID <

/ Param> delete from product where produter = @ ProductId SELECT ProductID, ProductName, ProductTypeID, currentCount, UnitName, ProductType.ProductTypeID, ProductType.ProductTypeName FROM Product, ProductType WHERE ProductID = @ ProductID AND ProductTypeID = ProductType.ProductTypeID 3) The structure of the entity object constructor is based on the above-described specification The developed XML is generated. These types of constructors implements the IClassBuilder interface. We predefine some standard Builder in the system core class, in general, directly using these standards of Builder. The design model of the class constructor used by the class constructor, if the user thinks that the standard Builder cannot meet

During the actual development process, we feel that the data entity layer has the following advantages in this design mode:

· Entity class definitions XML files can be automatically generated by tools, mitigating development workload.

• When performing query operations, both an entity is returned, or the manifestation of multiple entities, the manifestation of data is both ENTITYDATA, and there is no problem that the single object and data set as described above is not uniform.

• When modifying the definition of the entity, if the modified part does not involve the processing of business logic, you can only modify the XML file, you do not have to modify other programs and recompile.

· The physical object cache service provided by the system can greatly improve the performance of the system.

· The design model of the class construction plant has greatly improved the flexibility of the system.

Entity control layer

Solving and O-R MAP issues, it is necessary to consider the persistence problem of the entity class, that is, the interaction issue with the database. The physical control layer is used to control the basic operation of data, such as increasing, modifying, deleting, query, etc., while providing data services for the business rules layer.

The class of the entity control layer implements the IentityDao interface. This interface defines the main necessary methods of implementing data manipulation, including adding, modifying, deleting, and looking up. The definition of IAentityDao is as follows:

public interface IEntityDAO: IDisposable {void InsertEntity (EntityData entity); void UpdateEntity (EntityData entity); void DeleteEntity (EntityData entity); EntityData FindByPrimaryKey (object strKeyValue);}

It can be seen that this interface is very similar to the interface of EntityBean in J2EE. In fact, we also refer to EntityBean solutions.

Below is an example of a Product's DAO class:

public class ProductEntityDAO: IEntityDAO {private DBCommon db; // This is the class public ProductEntityDAO database access () {db = new DBCommon (); db.Open ();} public ProductEntityDAO (DBCommon cdb) {this.db = cdb; } // Insert an entity public void insertentity (entityData Entity) {checkdata; db.begintrans (); try {foreach (data ") DB.EXESQL (Row, Sqlmanager) DB.EXESQL (Row, Sqlmanager) DB.EXESQL (Row, SQLManager .Getsqlstruct ("product", "insertproduct")); db.committrans ();} catch (exception e) {db.rollbacktrans (); throw e;}} // Modify a physical class public void updateEntity (entityData Entity) {checkData (entity); db.BeginTrans (); try {foreach if (row.RowState = DataRowState.Unchanged!) db.exeSql (row, SqlManager.GetSqlStruct (DataRow row in entity.Tables [ "Product"] Rows.) ("Product", "UpdateProduct"); db.committrans ();} catch (exception e) {db.rollbacktrans (); throw e;}} // Delete a physical class public void deletentity (entityData entity) {checkdata (Entity); db.begintrans (); try {foreach (DATAROW ROW in Entity.tabl ES ["Product"]. Rows) DB.Exesql (Row, Sqlmanager.getsqlstruct ("Product", "DeleteProduct"); db.committrans ();} catch (exception e) {db.rollbacktrans (); throw e ;}} // find the entity class public EntityData findByPrimaryKey (object KeyValue) {EntityData entity = new EntityData ( "Product"); SqlStruct sqlProduct = SqlManager.GetSqlStruct ( "Product", "SelectByIDProduct"); db.FillEntity (sqlProduct.SqlString , sqlProduct.ParamsList [0], KeyValue, entity, "Product"); return entity;} public EntityData FindAllProduct () {EntityData entity = new EntityData ( "Product"); SqlStruct sqlProduct = SqlManager.GetSqlStruct ( "

Product "," FindAllProduct "); db.fillentity (SqlProduct.sqlstring, Null, Null, Entity," Product "); Return Entity;} // Verify data data Enter the validity void checkdata (entityData Entity) {i (entity.Tables [ "Product"] Rows [0] [ "ProductID"] ToString () Length> 40...) throw new ErrorClassPropertyException ( "Property ProductID should be less than 40 characters");} public void Dispose () {Dispose (True); gc.suppressFinalize (TRUE);} Protected Virtual Void Dispose (Bool Disposing) {if (! Disposing) Return; // We're Being Collected, So Let Thegc Take Care of this Object DB.Close The}}} The combination of the data entity is combined. These two parts realize the interaction of the application service layer with the database. These two parts are combined to complete the functionality similar to the EntityBean in J2EE.

Data entities and entities are used to separate design methods, with the following advantages:

· Avoid defects that manipulate the EntityBean system resource and low efficiency in the J2EE system.

· Resolved the overhead of using EntityBean transmission data in the J2EE system, and low-efficiency defects.

· You can modify the entity structure and the manipulation of the entity data, so that the system is more flexible.

· The class of the data entity XML definition file and the entity control layer can be generated automatically, and the development workload can be reduced.

Data Access Layer

In order to provide a service for the database for the physical control layer, we have designed this section. This level usually does the following:

· Connect to the database

· Execute database operations

· Query the database, return the result

· Maintain database connection cache

· Database transaction call

In order to unify the access method of the data, we include the data access service in the framework library, encapsulates the operations of various databases, which can access different types of databases, so that different types of databases can be accessed. When developing, you can use problems with the connection with the database, which also makes the application system when replacing the database, greatly simplifies the development and deployment work. Data Access Service also maintains database connection cache, improving system performance, and services to database transactions.

Data Access Service is primarily a service called to data access functionality in the core class library. The use of dbcommon can see one or two in ProductItemDao above. More can look at the use of DEMO projects.

Business rules

The function of the business rules needs to be completed is the implementation of various business rules and logic. Business rules complete this task such as the verification of customer accounts and book orders. This is the most complicated part of the entire application system, without too many laws. However, after we finish the above work, we can have a simplified job for this part of the development. This can be seen from the example below.

The design of the business rules usually needs a good modeling. Modeling of business rules, generally using UML. You can use UML sequence diagrams, state diagrams, activity diagrams, etc. to model business rules. This part of the work is usually done through interactions between a series of classes.

Business rules usually require the system to support transaction. In this place, .net provides a means of calling Windows Transaction Server. About this part, you read MSDN very clearly, and you will not do a detailed introduction. For example, in a stock system in a stock system, in addition to the need to save the storage list, before this, the number of products involved in the library must be modified, and the code is usually as follows (using transaction processing) ):

public void StoreIntoWarehouse (EntityData IndepotForm) {DataTable tbl = IndepotForm.Tables [ "InDepotFormDetail"]; try {ProductEntityDAO ped = new ProductEntityDAO (); for (int i = 0; i

Business appearance layer

The business appearance layer provides an interface for processing, browsing, and operations for web layers. The business appearance layer is used as an isolation layer that isolates the user interface to the implementation of various business functions.

The business appearance layer is just a system function that has been completed, and the business rules are high-level package according to the needs of each module.

The framework is not specified in the implementation of the business appearance layer, but it is recommended to use Web Service to provide services. Using IIS as a web server, it can be easily deployed Web Service.

· Web layer

The Web layer provides access to the application for the client. The Web layer consists of an ASP.NET web form and code hidden file. The web form is just a user operation with HTML, and the code hidden file implements event processing of various controls.

Typically, for the ASP.NET web form and control event processing code for the data maintenance type, we provide tools to generate and reduce development efforts.

In addition to the above six logic layers, the system typically includes a system configuration item, providing an application configuration and tracking class.

Frame service design strategy

In order to be able to support the system architecture described above, we need a core class library to achieve support for the application software to construct it. Thus, when the development of each application system, many basic work can be omitted to improve the efficiency of development. In this regard, we designed the following core classes and interfaces:

· EntityData: Universal Structure for Defining the Entity Class · IclassBuilder: Defines the structure of the physical classes structure. We predefined several standard classes implemented according to this interface: AbstractClassBuilder, SingletableClassBuilder, ThickClassBuilder, StandardClassBuilder. These Builders are managed by ClassBuilderFactory.

· IENTITYDAO: Defines the interface of the entity control class

· EntityDataManager: Provides cache management and search service for all entity classes

· DBCOMMON: Package database operation

· ApplicationConfiguration: Record System Configuration

· SQLManager: Manage the SQL statement of the system and its parameters.

Through these core classes and interfaces, the framework can provide the following services for the application:

· O-R Map: Object - Relationship Database Mapping Service

转载请注明原文地址:https://www.9cbs.com/read-82695.html

New Post(0)