3 tier architecture in asp.net

7
In this asp.net tutorial you will learn how to implement 3-tier architecture in asp.net using c#. 3-Tier architecture is also called layered architecture . Some people called it n-tier architecture . Layer architectures are essentially objects and work in object oriented environment just like asp.net. 3- tier architecture is a very well known architecture in the world of software development, it doesn't matter whether you are developing web based application or desktop based, it is the best architecture to use. 3-Tier Architecture in asp.net using c# 3-Tier architecture consists of 1) UI or Presentation Layer 2) Business Access Layer or Business Logic Layer 3) Data Access Layer Presentation Layer Presentation layer consists of pages like .aspx or desktop based form where data is presented to users or getting input from users. Business Logic layer or Business Access Layer Business logic layer contains all of the business logic. Its responsibility is to validate the business rules of the component and communicating with the Data

description

Tier Explained Simply

Transcript of 3 tier architecture in asp.net

Page 1: 3 tier architecture in asp.net

In this asp.net tutorial you will learn how to implement 3-tier architecture in asp.net using c#. 3-Tier architecture is also called layered architecture. Some people called it n-tier architecture. Layer architectures are essentially objects and work in object oriented environment just like asp.net. 3-tier architecture is a very well known architecture in the world of software development, it doesn't matter whether you are developing web based application or desktop based, it is the best architecture to use.

3-Tier Architecture in asp.net using c#

3-Tier architecture consists of1) UI or Presentation Layer2) Business Access Layer or Business Logic Layer3) Data Access Layer

Presentation LayerPresentation layer consists of pages like .aspx or desktop based form where data is presented to users or getting input from users.

Business Logic layer or Business Access LayerBusiness logic layer contains all of the business logic. Its responsibility is to validate the business rules of the component and communicating with the Data Access Layer. Business Logic Layer is the class in which we write functions that get data from Presentation Layer and send that data to database through Data Access Layer.

Data Access LayerData Access Layer is also the class that contains methods to enable business logic layer to

Page 2: 3 tier architecture in asp.net

connect the data and perform desired actions. These desired actions can be selecting, inserting, updating and deleting the data. DAL accepts the data from BAL and sends it to the database or DAL gets the data from the database and sends it to the business layer. In short, its responsibility is to communicate with the backend structure.

Illustration of 3-Tier Architecture with Diagram

The figure clearly describe about the purpose of BAL and DAL. The main advantage of 3-tier architecture is to separate the presentation layer from data access layer. You will not write any function to communicate with database in presentation layer, all the required functions for communication with database will be available in DataAcessLayer. Its mean at presentation layer you will just focus at information that you will present in front of user.

I am going to create BAL, DAL in App_Code folder. You can also create separate projects for BAL, DAL and UI (Your website) and referenced your DAL into BAL and BAL into UI. In that scenario you have to rebuild the DAL and BAL every time, in order to view the change that you have made in your BAL and DAL. So to get rid of rebuilding layers every time after change, I am going to create BAL and DAL folder in App_Code. Now feel free to make changes in BAL and DAL and just refresh the webpage to view the change that you made, in short no rebuilding of DAL and BAL is required. The following figure shows the 3-tier architecture of our website that we are going to made.

Page 3: 3 tier architecture in asp.net

Design and implement 3-tier architecture

.

1) Open visual studio or visual web developer.2) Go to File-> New Web Site

3) Select ASP.NET Web Site and then browse the Folder in which you want to save your web pages.

Page 4: 3 tier architecture in asp.net

4) Go to Solution Explorer and then right click on your website folder.

Go to Add ASP.NET Folder-> App_Code.

5) Now right click on App_Code Folder and select New Folder.

6) Create Two Folders and give BusinessLayer and DataAccessLayer names to them.

Page 5: 3 tier architecture in asp.net

7) Now right click on DataAccessLayer -> Add New Item.

8) Select Class as template and give DbAccess name to that class.

9) Now right click on BusinessLayer folder-> Add New Item

Page 6: 3 tier architecture in asp.net

10) Select Class as template and give BusComments.cs name to that class.

Now open your DbAccess.cs file placed in DataAccessLayer folder. Clear it by deleting all its built-in code and then copy/paste the following code in your DbAccess.cs file and then save it