3 Tier Architecture in .NET - Sample Application

3 Tier Architecture in .NET - Sample Application

In this article we are going to look on how to create a 3 tier architecture application in .NET.

Basically three tier architecture needs to 3 projects to be created.
1. UI Layer
a. All you UI related stuffs like pages, user controls, CSS and java scripts will go into this.
2. Business Layer
a. All business rules are performed here.
3. Data Access Layer
a.All data access code like connecting to database and getting the details are done here.
4. Apart from these three projects, we will be having one more project called as Model. This will have all model classes which we use it in out application

It's not a good idea if you pass a dataset or data table from the DAL to the UI. We need to map those table fields to our custom class and we need to pass the custom object from the data access layer to UI. This is what we called ORM (Object Relational Mapping).

These things will come into picture like whenever, you want to expose your BAL through the Web Services, you can quite easily do that. And putting the model classes will make your code maintenance much easier. This will give the programmer to expand the current functionality of the classes when they are needed.

That's where the model classes come to the picture. I have 2 model classes used for this demo.
1. Employee.cs
a. This is a base class. Whenever we need to pass and get the employee details, we will be using this class.
2. EmployeeCollection.cs
a. This class is inherited from Collection which will hold the collection of Employee objects.
When you want to get the detail of one employee, then you can make use of Employee class. When you need to get the collection of the empoyees, you can use the EmployeeCollection. I have inherited from Collection,so that I can make the class as a strongly typed collection object. Thought of implementing the IList for this, but I dropped that because Collection already implements the ILIst, ICollection and IEnumerable. That made my life easier in creating a sample application.

This application is developed using VS2005 and ASP.NET 2.0. Make sure you have Web Project Template installed in your machine else, you won't be able to open this application.

I have attached the demo application of 3 tiers. You can just download it and how a look how exactly we can implement the 3 tier architecture in the projects.

This is basic for n-tier architecture need to think more when you design your project on how to implement the tiered architecture.

Please feel free to post your queries. I will always be happy to answer and respond to your query.

By,
Brainstorming Guy aka Venkatarajan A


Attachments

  • 3 Tier Architecture - Demo Project (19462-7751-ThreeTierArchitectureDemo.zip)
  • Comments

    Author: Sheo Narayan17 Jul 2008 Member Level: Gold   Points : 1

    See details step wise tutorials of 3-tier architecture

    http://dotnetfunda.com/articles/article71.aspx

    Author: Brainstorming Guy18 Jul 2008 Member Level: Gold   Points : 2

    Hi Narayan,
    I don't see it as a tiered architecture. It looks like a layered one.
    As you know, there not much option provided here to attach some imaged with give link. ( or i may not be knowing how to do that).
    Anyway, thanks for it man. Will look into that.

    Regards,
    Brainstorming Guy aka Venkatarajan A

    Author: Sheo Narayan18 Jul 2008 Member Level: Gold   Points : 2

    Ah, I got your point. For the ease of understanding in that article, I have created BAL and DAL into App_Code folder. I have specified this in the article too.

    In real scenario, all 3-Tiers (BAL, DAL and UI) should have 3 separate projects.

    Thanks for pointing this out.

    Regards,
    Sheo Narayan

    Author: Brainstorming Guy18 Jul 2008 Member Level: Gold   Points : 1

    Thanks Man.
    Anyway, article looks good.
    Thanks for providing it.

    Regards,
    Brainstorming Guy aka Venkatarajan A

    Author: Ashish Shah19 Jul 2008 Member Level: Gold   Points : 2

    Hello,

    Its not looks too good for articla in this level of site..

    I think there is much information and concept can add in this one..

    Very basic and little information with less explanation..
    Anyway still good work to write..!!

    Better luck next time ..

    With Regards..

    Ashish Shah
    India,Surat

    Author: Brainstorming Guy26 Nov 2009 Member Level: Gold   Points : 1

    removed the post which was made by mistake.

    Author: jatin05 Apr 2011 Member Level: Bronze   Points : 1

    This is very helpful to me.......for better understanding of three tier architecture you can visit following link....

    www.dotnetpeoples.blogspot.com/2011/04/three-tier-architecture-in-aspnet.html

    Guest Author: Shmul01 Aug 2012

    Thank you, finally easy, clean, downloadable example of layers on the web!



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: