Actual Secret: .Net platform application development framework of the system: SUN Ya-min www.ASPCool.com Time: 2003-7-9 20:59:46 Views: 7967
Author: SUN Ya-min This article taken from: CCID Microsoft's .Net platform for application development provides a very good foundation platform, but how to build their own applications on this platform, we also need for the application system Features, build your own application system framework (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 system, we can usually divide the system into the following three levels: • Database layer · User interface layer · Application service layer For application system, in these three hierarchical, system main Features and business logic processing in the application service layer, for the system framework, the main process 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 expression of the entity class, and the corresponding relationship with the database, that is, the so-called so-called OR 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 with the above problems can be used to refer to the following: Hierarchical problem data entity layer data representation of physical control layer data access layer provides access to the database, encapsulates ADO.NET business rule layer business logic organization The structural diagrams of the way the service appearance layer business service is the structure diagram of the entire system: the arrow in the figure indicates that the use relationship will divide the system into so many layers, and the advantage is capable of making the system's architecture clearer, so that each level is completed Comparing single, functional code is rules, which means we can develop some tools to generate these code, reducing the workload of code written, enabling developers to put more energy on 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 detail the design and strategy of each part as follows: Data entity layer We first need to solve the problem of data representation, which is the usual O-R Map problem. Or 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 product {string productId; string product; float account;} may have a corresponding one in the database Product Table: Field Name Data Type ProductID VARCHAR (40) ProductName Varchar (50) Account Float This is the most common practice, but this way brings 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 inherits the DataSet, adds some methods to the framework of all entity classes, define each entity class. General structure, as for each entity class specific structure, determined by the following method: 2) The definition of the entity class is determined by the XML file, the XML file conforms to the JIXML object entity description language specification (Note: jixml is us Object-entity mapping language for determining the structure of the entity class. For example, a definition of the entity class of the order may be similar to the following structure: 3) The structure of the entity object is generated according to the XML of the above specification by a series of classes.
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 does not meet the requirements, you can extend the IClassBuilder interface, write your own class constructor, and then specify a variety of constructors in the system configuration file. Name. IClassBuilder defined as follows: public interface IClassBuilder {EntityData BuildClass (string strClassName); // get a class data structure SqlStruct GetSqlStruct (string strClassName, string strSqlName);} structure of this moiety can be represented by the class diagram as follows: When a user needs When the entity class, as long as the following statement is adopted: entityData entity = entityDataManager.GeteTyentity ("product"); EntityDataManager's getEmptyEntity method is implemented by calling ClassBuilder's buildClass and implements the cache function of the object. ClassBuilder implemented method of BuildClass follows: public EntityData BuildClass (string strClassName) {IClassBuilder builder = ClassBuilderFactory.GetClassBuilder (strClassName); return builder.BuildClass (strClassName);} Here Factory Builder and using a combination of design patterns. The role of ClassBuilderFactory is based on the name of the entity class, the specific class name of the corresponding class fabric in the configuration file, and returns the specific class constructor. The configuration file classbuilders.xml is simple: XML version = "1.0" encoding = "gb2312"?>
• 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 solves and O-R MAP problems, it is necessary to consider the persistence problem of entity classes, that is, the interaction 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. IEntityDAO defined as follows: public interface IEntityDAO: IDisposable {void InsertEntity (EntityData entity); void UpdateEntity (EntityData entity); void DeleteEntity (EntityData entity); EntityData FindByPrimaryKey (object strKeyValue);} can be seen, this interface with the J2EE EntityBean The interface definition is very like, in fact, we also refer to the EntityBean solution.
The following is an example of a Product of the DAO classes: public class ProductEntityDAO: IEntityDAO {private DBCommon db; // This is the class public database access ProductEntityDAO () {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 (DataRow Row in Entity.tables ["Product"] .Rows) db.exesql (Row, Sqlmanager.getsqlstruct ("Product", "InsertProduct"); db.committrans ();} catch (exception e) {db.rollbacktrans (); throw e;}} // Modify an entity class public void UpdateEntity (EntityData entity) {checkData (entity); db.BeginTrans (); try {foreach (DataRow row in entity.Tables [ "Product"] Rows.) if (row.RowState = DataRowState.Unchanged! ) DB.EXESQL (Row, SqlManager.getsqlstruct ("Product", "UpdateProduct")); db.committrans ();} catch (exception e) {db.rollbacktrans (); throw e;}} // Delete one Entity class public void DeleteEntity (EntityData entity) {CheckData (entity); db.BeginTrans (); try {foreach (. DataRow row in entity.Tables [ "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;} // private void check the validity of the data input checkData (EntityData entity ) {. if (.. 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 combination of the data entity is combined with the data entity, which implements the application service layer interaction with the database. These two parts are combined to complete the functionality similar to the EntityBean in J2EE. Using data entities and entities control separate design methods, with the following advantages: Avoid defects that manipulate the EntityBean system resource consumption 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 manipulation of the entity data, so that the system is more flexible and the data entity's XML definition file and entity control layer can be automatically generated, and the development workload can be reduced. The data access layer provides services to the database operations for the entity control layer, we design this part. This level usually does the following: • Connect the database · Execute database operation · Query database, return results · Maintain Database Connection Cache · Database Transaction Call To unify the data of data, we are designing, in the framework library The data access service contains the commonly used database operations, which can access different types of databases, so that when the specific software system is developed, it is possible to replace the application with the database. During the database, you don't have to modify the original code, greatly simplify 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. The functionality of the business rules level business rules 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 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. • The Web layer web layer provides access to the app 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. The design strategy of framework services In order to support the system architecture described above, we need a core class library to achieve support for applications that 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 of the entity class · iClassBuilder: Defines the structure of the physical class 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. Through these core classes and interfaces, the framework provides the following services for the application: · Or map: Object-Relational Database Mapping Services This section completes the mapping of entity objects in the application, mainly providing data for data entity . In this section, a Jixml entity-object mapping language is defined. This is a specific language we developed using XML to describe mappings between object-entities. Developers can use it to describe object-entity mapping relationships. Developers can also directly extend the codebuilder interface, manually complete the code of the object - entity mapping relationship. The system is modified according to the setting of the configuration file at runtime, and the structure of the entity object is dynamically constructed. · Database Access: Database Access Service This section provides services to database access. The application software system built on this framework is not directly manipulated, but is performed by the data access service provided by the class library. Database Access Service As an intermediaries between the application with the database, it is possible to effectively prevent the insecure operation of the database. Database Access Services also provides a calling method for database library transaction processing, developers can easily call the transaction function of the database through the Database Access Service. · DML Search: Data Manipulation Schedule Query Service In the system architecture, the SQL statement that operates on the database is not embodied in the program, but is described in the XML file as the physical class structure of the data entity layer, which conforms to the JIXML specification.