How To Create Three-Layer Architecture Of ASP.NET Application

In this article, I am going to explain how to create 3-layer architecture of an ASP.NET application.

Introduction

Three-layer architecture is made of Presentation, Business, and Data access layer. In this article, I will create three-layer architecture with the help of a simple ASP.NET application. You can understand the importance of these three layers with the help of complete article.

ASP.NET
Figure 1 3-Layers architecture

In the three layers architecture, as you can see, Presentation layer and business layer communicate with each other, and business layer (Controller) and data access layer (Model) communicate with each other.

Understand each  layer one by one

Presentation Layer

The presentation layer is used to display the data to the users. Your .html or .aspx Pages are presentation layer which shows data to the users. Add one web application project to solution and give the name Presentation layer to it. Add one web page as I did in the below image.

ASP.NET
Figure 2 (Presentation Layer)

Business Layer  

This is the middle layer which communicates with Presentation and data access Layers. Business layer sends a request to Data layer for data and sends data to the presentation layer to display to the end user. In this layer, we write business logic. Now, it is time to create a business layer. Let us add one class library to create a business layer and give the name BusinessLayer to it as I did in the below Image.

ASP.NET
Figure 3 Class Library Project

Now, your solution looks like the below image. In the solution, I have two projects - one is my “PresentationLayer” project and the second one is my “BusinessLayer” project.

ASP.NET
Figure - 4 ( Solution Explorer with two projects)

Data Access Layer

Data access layer communicates with the database as well as the presentation layer. Presentation layer sends a request to data access layer and data access layer sends a request to the database to get data and returns the data to presentation layer in the form of the object, list, array etc. Now, it is time to create a data access layer by adding one more class library and give name “DataAccess” to it as I have added in the below image.

ASP.NET
Figure-5 (Solution Explorer with all three Projects)

We have to add one business object layer. Same, we will add one more class library. Later on, I will discuss the importance of this “BusinesObj” library. Now, as you can see in the below image, each class library is having one default class “class1”. Delete this class from all the class library projects.

ASP.NET
Figure-6 (Solution Explorer with all three layers)

Now, add the reference of your project.

  1. Add “BusinessObj” project reference to “BusinessLayer”,”DataAccess” and “Presentation layer” projects.

Steps to add reference 

    1. Right click on reference option of your project (BusinessLayer, DataAccess, and Presentation layer).
    2. Click on Add Reference option.

      ASP.NET
      Figure-7 add Project ref(1)

    3. Select the project option from the left hand side menu and check on “BusinessObj” project and click ok option.

      ASP.NET
      Figure-8 add Project ref(2)

    4. Now, check your reference of “BusinessObj” project inside the References option of your “BusinessLayer” project .

      ASP.NET
      Figure-9 Businessobj ref added to BusinessLayer

    5. Similar steps you have to follow for the remaining applications(DataAccess , Presentation layer) to add the “BusinessObj” project reference.
  1. Add “BusinessLayer” project reference to “PresentationLayer” Project by doing the same process.

    ASP.NET
    Figure:-10 BusinessLayer ref added to PresentationLayer
  1. Add “DataAccess” project reference to “BusinessLayer” project.

    ASP.NET
    Figure:-10 DataAccess project ref added to BusinessLayer

Now, we have created a project with three-layer architecture. Each layer will play a significant role in the project. We will understand the use of each layer. I will discuss implementation in the next article.                       


Similar Articles