Introduction: In this article i
am going to explain How to setup/configure or implement a 3-tier/layer
application in Asp.Net.
Description: 3-Tier architecture
is also called layered architecture. In 3 tier
architecture, the application development is broken into three main parts:
- Presentation Layer or Application layer or User Interface (UI).
- Business Access Layer (BAL) or Business Logic Layer.
- Data Access Layer (DAL).
This separation into layers ensures independent development of
each layers and any changes in one layer doesn't affect the other layers.
Application Layer or Presentation
Layer or user Interface (UI): It is the part of the 3 tier architecture with
which the end user actually interacts. This layer contains pages like .aspx (
in case of web application) or windows form where data is presented to the user
or input is taken from the user e.g. Registration form or any user input form. We can say that it is the front end of
the application.
Business Access Layer (BAL) or
Business Logic Layer (BLL) : This Layer is the class in which we write
functions that accepts data from Presentation Layer and send that data to
database through Data Access Layer. Presentation layers must not directly
access the data access layers. So this layers acts as a intermediate between
Presentation Layer and Data Access layer.
Data Access Layer (DAL) :
This layer also contain classes that actually deals with the database and is
responsible for performing database operation like insertion, deletion,
updation and Binding etc.
DAL accepts the data from
BAL and sends it to the database for processing or we can say DAL gets the data
from the database and returns it to the business layer (BAL) to be sent to the
front end.
We will also create a Business
Entity layer (BEL) or we can say property layer having properties for each
column in the table. So if we have 5 columns in table then we declare 5 property/parameters in this layers so that we can set the value taken from UI in these parameters and then sent to DAL via BLL.
For example, from the form in application layers, we take the user input and put those values in parameters declared in BEL and then they will be passed to the DAL through the BLL.
For example, from the form in application layers, we take the user input and put those values in parameters declared in BEL and then they will be passed to the DAL through the BLL.
Main benefit of creating this Entity layer is that we declare the properties/parameters only once in this layer and these properties/parameters can be accessible throughout the project by creating the object of BEL class. Don't get confused, it will be cleared when we will implement it.
Implementation: Let's implement the concept of 3 tier web application.
Launch Visual Studio -> File
Menu -> New -> Project -> go to Other Project Types -> Select
Visual Studio Solutions and Name it "3TierBookApp" or whatever
you want as shown in image below.
Click on image to enlarge |
Adding Presentation layer
In Solution Explorer, right click
on the solution just created -> Add -> New Project. A dialog box will appear.
Select the language Visual C# -> Web -> ASP.NET Empty Application. Name
it "Presentation_BookApp" or whatever you want as shown in image below.
Click on image to enlarge |
Adding Business Entity Layer (BEL)
Again right click on the solution
in the solution explorer -> Add -> New Project -> Visual C# ->
Class Library -> Name it "BEL_BookApp" or as whatever you want as
shown in image below
Click on image to enlarge |
Adding Business Login layer (BLL)
Again right click on the solution
in the solution explorer -> Add -> New Project -> Visual C# ->
Class Library -> Name it "BLL_BookApp" or whatever you want as
shown in image below.
Click on image to enlarge |
Adding Data Access Layer (DAL)
Again right click on the solution
in the solution explorer -> Add -> New Project -> Visual C# ->
Class Library -> Name it "DAL_BookApp" or whatever you want as
shown in image below
Click on image to enlarge |
That's way we have configured our
3 tier architecture. It will look like as shown in image below.
Click on image to enlarge |
Remove the default class1 from
all the BEL, BLL and DLL layers. We can create our own classes as per
application requirement.
Adding required References
Now we need to add reference of BEL
and BLL in the Presentation layer so that presentation tier can communicate
with BEL and BLL. So right click on the
"Presentation_BookApp" in the solution explorer -> Add Reference
-> A dialog box will appear. Select BEL and BLL as shown in image below.
Click on image to enlarge |
Similarly add reference of BEL in
DAL using the same process as mentioned above. And also add reference of BEL
and DAL in BLL. We have setup our 3 tier project. But actual implementation will be clear when we create an application using this setup.
So in the next step we will learn How to create 3tier application to Insert, Edit, update, Bind and Delete book records usingAsp.Net C# and Sql Server as a back end database.
Now over to you:
I hope you have got how to setup 3 tier architecture to create a project in asp.net and If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linked in and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates.
15 comments
Click here for commentsLike the post... Keep up the good work.
ReplyHello A1785..thanks for appreciating my work..stay connected and keep reading..:)
ReplyVery Nice Post......
ReplyBut Lalit Sir
I want to know what are the advantages of 3 Tier Architecture. How it is better than simple program.
good post..
ReplyI had more knowledge about 3 Tier Architecture,,
and open my mind about 3 tier concept for build application.
thanks..
Hello Dimar Candra..thanks for appreciating this article..stay connected and keep reading for more useful updates like this..:)
Replyhello Lalit Sir,
ReplyI have query about calculating attendence for an employee, i wnt to calculate it according the hours he logged in and wht tym he logged out.
and sir i am getting error in the remember me check box: SqlDataReader dr = adp.SelectCommand.ExecuteReader();
if (dr.HasRows)
{
if (chkRemember.Checked)
it says tht chkRemember is does not exist in current context
please help for these two queries...
Thank you.
Best one tried without errors
ReplyThanks Shashikanth for your feedback..i am glad you found this article helpful..stay connected and keep reading for more useful updates...:)
Replythanks for the post, continue your article
ReplyGreat Article..I really appreciate your Way of try to make understand.
ReplyThanks a Lot
Thanks Javed Akhtar.. It is always nice to hear that my articles helped anyone..stay connected and keep reading..:)
ReplyCurrently I'm reading a book on developing 3 tier applications in VB.net. Your article explains better than that.. So simple and precise.. Well done Sir.. 😊
ReplyThanks for your valuable feedback..i am glad my article helped you in understanding 3-tier architecture.Stay connected and keep reading for more updates.
Replythanks alot u article help me alot
Replyhi
ReplyIf you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..