Research on creating a three-tier architecture development model and three-tier architecture with vs2010

Source: Internet
Author: User
Tags asp net visual studio 2010

Research on layer-3 Architecture

 

Concept of three-tier architecture

  1. User Interface presentation layer (USL)
  2. Business logic layer (BLL)
  3. Data access layer (DAL)


Bll separates usl from dal and adds Business Rules

 
  • Role of each layer
  • 1: Data access layer: mainly refers to the operation layer for raw data (in the form of storing data such as databases or text files), rather than raw data, that is, it refers to data operations, instead of databases, it provides data services for the business logic layer or presentation layer.

    2: business logic layer: This layer is mainly used to address specific problems. It can also be understood as a pair of operations on the data layer. If the data layer is a building block, the logical layer is the construction of these blocks.

    3: Presentation Layer: It mainly indicates the Web mode or winform mode. The Web mode can also be represented as Aspx. If the logic layer is quite powerful and complete, the logic layer provides complete services regardless of how the presentation layer is defined and changed.
 
  • Specific differentiation methods

    1: Data access layer: it mainly depends on whether your data layer contains logic processing. In fact, its functions mainly perform operations on data files. You do not have to worry about other operations.

    2: business logic layer: mainly responsible for operations on the data layer. That is to say, some data layer operations are combined.

    3: Presentation Layer: This layer mainly accepts user requests and returns data to provide client access to applications.
 
  • Layer-3 structure explanation

    The layer-3 architecture adds an intermediate layer between the client and the database, also known as the component layer. The layer-3 system mentioned here does not refer to the layer-3 physical architecture, instead of simply placing three machines as the layer-3 architecture, or not just B/S applications as the layer-3 architecture, layer 3 refers to the logic layer 3, even if these three layers are placed on one machine. Applications in the layer-3 system put business rules, data access, and legality verification into the middle layer for processing. Normally, the client does not directly interact with the database, but establishes a connection with the middle layer through COM/DCOM communication, and then exchanges with the database through the middle layer.

    Developers can place the business logic of an application on the application server in the middle layer and separate the business logic of the application from the user interface. Provides a simple interface while ensuring the client functions. This means that if you need to modify the application code, you only need to modify the intermediate application server, instead of modifying thousands of client applications. This allows developers to focus on the analysis, design, and development of the core business logic of the application system, simplifying the development, update, and upgrade of the application system.
 
  • So why should we apply the "intermediate business layer? For example:
    Assume that there is a piece of login code, you can process the web program in this way. The appearance layer is responsible for receiving the data on the front-end page, and then passing it to the middle layer. The middle layer processes the data, such as formatting, anti-SQL injection and so on. Such data is then transmitted to the data access layer and then operated with the database, such as matching the database user name and password and other code.


  • The "intermediate business layer" has many functions, such as verifying user input data and caching data read from the database ...... However, the actual purpose of the "intermediate business layer" is to combine the basic storage logic of the "data access layer" to form a business rule. For example, "a shopping website has such a rule: the system automatically registers users who shop for the first time on the website ". Such business logic is most suitable in the middle layer:

In the "data access layer", it is best not to see any "business logic "! That is to say, to ensure the atomicity of function functions in the "data access layer! That is, the minimum and no score is allowed. The "data access layer" only stores or reads data.

 
  • Three-layer structure in ASP. NET

    The requirements for a complete three-tier structure are:Modify the presentation layer without modifying the logic layer, instead of modifying the data layer.Otherwise, it is hard to say whether your application has a multi-layer structure, or whether there is a problem with the Division and organization of the layer structure. Different applications have different understandings. This is just a conceptual question.
  • Understanding the three-tier structure in ASP. NET-- Why is it three layers?

    We use a three-tier structure to make the project structure clearer and the division of labor clearer, which is conducive to later maintenance and upgrade. It may not improve the performance, because when the subprogram module is not executed, the main program module can only be in the waiting state. This shows that dividing an application into layers will cause some loss in its execution speed. However, from the perspective of team development efficiency, we can feel a big difference.


    It should be noted that the layer-3 structure is neither a. Net patent nor a technology dedicated to databases. It is a more universal architecture design concept.
 


This architecturePay attention to the relationship between tables in database design,Try your best to satisfy the relationship between the master and the child. Users must have certain functional limitations. do not exercise caution when deleting sub-tables, in this case, the foreign keys of the primary table that are logically present in the data of the primary table and the sub-table do not have the corresponding values in the sub-table.

  • ForComprehensive QueryThe method is:
    First, query the master table and call the DL corresponding to the master table. Query each sub-table based on the records of the master table. A large query set is formed after the query result of the Self-table is added to the master table.
    Operations on tables (add, delete, and modify ):
    In this case, only the primary table is operated and the operation method in the DL corresponding to the primary table is called.
    The RL layer is the logical judgment layer, mainly used to perform logical judgment on the data uploaded to the page. Above the RL layer is the UI

  • How to build a three-tier architecture solution

    Create a blank solution. Then:
    "Add"-"New Project"-"Other Projects"-"Enterprise template project"-"C # generate blocks"-"Data Access" (data layer, hereinafter referred to as layer D)
    "Add"-"New Project"-"Other Projects"-"Enterprise template project"-"C # generate blocks"-"Business Rules" (business layer, hereinafter referred to as layer C)
    "Add"-"New Project"-"Other Projects"-"Enterprise template project"-"C # generate blocks"-"Web User Interface" (interface layer, (U layer)
    Right-click solution-ProjectDependency", Set u to depend on D, C, and C to depend on D.
    Add references D and C to U, and add references d to C.
    So far, a three-tier shelf has been established. What I said above is very specific and "stupid". People who know me think I am nonsense. In fact, during this time, I strongly felt that many people actually did not understand this simple process. Although there is no objection to creating two "Empty Projects" and one "asp net Web Application Project", it can also be used as a three-layer framework, many people think that these "enterprise-level template Projects" are actually empty projects, which is a misunderstanding. Yes, you can see from the solution resource manager that there is nothing in the enterprise-level template project. But you can open the project file in notepad and see the difference ?? You can't see some things behind the scenes, but the system is ready. That is to say, if you "using system data sqlclineit" in a class in the C layer or use a sqlconnection object, no errors will occur during compilation, however, some "policy warnings" will be generated in the "task list" to warn you not to put things that should be placed on layer d in the C layer (although the program is correct, but the readability and maintainability are discounted.) This function cannot be provided to empty projects.
  • In the new tracelword3, the "enterprise-level template project" is applied ". Place the original lwordtask. CS in a single project named accesstask. In the solution, a new project named interservice is created, which contains an lwordservice. CS program file, which is the "intermediate business layer" program. To avoid repeated names, the tracelword3 website is placed in the webui project. For more complete code, you can find it in the codepackage/tracelword3 directory --

  • Combination of face object and reality

  • We know that building a bridge requires bricks. We should first prepare bricks and then build the bridge. However, in order to explain the sequence and consistency, it is simple. We should first build a bridge and reproduce the bricks during the construction process, so that there will be no more "things not needed by the bridge ". In practice, you should prepare bricks first.
    The U layer is actually a bridge, the C layer is a brick, and the D layer is a raw material (stone, sand ). This also explains why the U layer references and depends on the D Layer (instead of the U-to-C and C-to-D layers), because the bridge requires both bricks and stones.
 
  • Disadvantages of "three-tier structure"
  • Some netizens raised some questions after reading this article, reminding me that the article has not mentioned the disadvantages of "three-layer structure. The word "three-layer structure" seems to have been popular all the time. The reason may be that this development mode is widely used. However, the "three-layer structure" is not a hundred trials of the "Wan Ling medicine", it also has shortcomings. Let's talk about its shortcomings ......

    One obvious disadvantage of the "three-tier structure" development model is that it does not run fast enough. Of course, this "execution speed" is relative to non-hierarchical applications. According to the sequence diagram given in sequence, this disadvantage is also obviously exposed. Tracelword1 and tracelword2 are not layered, And the classes provided by ADO. NET are called directly to obtain data. However, tracelword6 does need to be called multiple times to obtain data. When the subroutine Module Program does not return, the main program module can only be in the waiting state. Therefore, the higher the message board version, the lower the ranking. The "three-tier structure" development model is not applicable to systems that require too much execution speed, such as online ticket booking, online stock trading, and so on ...... It is better at systems where business rules are easy to change.

    The "three-tier structure" development mode is difficult to get started and difficult to understand and learn. This is intended for beginners. The amount of code for software developed in this mode is usually slightly higher. This will often overwhelm beginners in the vast amount of code. It is understandable that you are afraid of it ......

    In fact, no matter which development mode or method it is, there are advantages and disadvantages. There is no "Universal Method" to solve any problem. Therefore, the word "three-layer structure" is not an exception! Whether to use this mode for system development requires comparison and trade-offs. Do not abuse it!

  Create a three-tier architecture development mode with vs2010

 

1. Open vs2010 --- create a solution-I use a typical three-tier architecture as an example to divide it into the UI Layer, BLL layer, and Dal layer.

2. Add three projects:

Set webui as the startup item, and set dependencies for each layer. Bll depends on Dal, and UI depends on BLL. Click-menu bar-project-Project dependency

3. Export each project-file-export template.

Export the other two layers in the same way. Now let's open the folder at the export location,

3. Decompress each folder.

 

4. Open notepad and enter the following code:

<Vstemplate version = "3.0.0" = "http://schemas.microsoft.com/developer/vstemplate/2005" type = "projectgroup">
<Templatedata>
<Name> three-tier architecture template </Name>
<Description> & lt; layer-3 architecture project & gt; </description>
<Projecttype> CSHARP </projecttype>
<Sortorder> 1000 </sortorder>
<Createnewfolder> true </createnewfolder>
<Defaultname> template </defaultname>
<Providedefaultname> true </providedefaname Name>
<Locationfield> enabled </locationfield>
<Enablelocationbrowsebutton> true </enablelocationbrowsebutton>
</Templatedata>
<Templatecontent>
<Projectcollection>
<Projecttemplatelink projectname = "webui"> webui \ mytemplate. vstemplate </projecttemplatelink>
<Projecttemplatelink projectname = "BLL"> BLL \ mytemplate. vstemplate </projecttemplatelink>
<Projecttemplatelink projectname = "Dal"> Dal \ mytemplate. vstemplate </projecttemplatelink>
</Projectcollection>
</Templatecontent>
</Vstemplate>

And save it as the mytemplate. vstemplate file.

5.merge and package ---select bll、daland webuiand mytemplate.vstemplateand compress it as the threetier.zip file.

 

6. Copy or cut the compressed zip file to the C: user \ your username \ Documents \ Visual Studio 2010 \ Templates \ projecttemplates folder.

 

7. This is the template displayed when you open vs2010 to create a project.

Of course, you can also add basic references in advance. For example, the sqlclient that Dal may use can be added before the template is exported.

Research on creating a three-tier architecture development model and three-tier architecture with vs2010

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.