locked
Is my idea for 3 Tier Architecture correct? RRS feed

  • Question

  • User515645503 posted

    Hi all,

    New to the forum, looking to learn a lot! Ok, so this is some backround. We have a classic ASP Intranet. I want to rewrite the whole thing in C# ASP.NET 3.5. Going to develop it as a website and not a web application because our Intranet is huge, made up of many parts, and updates will be needed to be done without having to bring down the Intranet to re-compile it etc. So a web application is not an option here as a website can have the page in question updated without downtime of the Intranet needed. With regards to SQL Server 2008, Im going to make use of stored procedures in the new Intranet.

    Ok, so now thats explained, I did some reading up on 3 tier achritecture. Im new to .NET, so want to do this correct from the beginning. Most resources I read said to actually create seperate websites for the Presentation Layer, Business Logic Layer and Data Access Layer. Others state to create 1 website, and in the APP_Code folder, create 2 folders (1 BLL and the other DAL) and then add the class files there as needed. I dont like this approach, I think the first is better (split each layer into seperate websites and then refernce them as needed in the main Intranet website).

    So, my idea for the 3 tier architecture is:

    1. Create a main Intranet website project. This will be the Presentation Layer and will serve as the frame/backbone of the Intranet. Due to how big our Intranet is I will create seperate website projects for meeting room bookings, classifieds, telephone directory etc (there are just too many sections to list them all). So if I need to change, for example, HTML in the search results page in the telephone directory I can open the telephone directory website project, make the change there, save it and be done. The rest of the Intranet wont be affected.

    2. To the main Intranet website (as described above), I will reference the BBL and DAL as and when needed.

    3. I will create a seperate Business Logic Layer website project. In this website project, add classes for each section of the Intranet (TelephoneDirectoryBLL.cs, ClassifiedsBLL.cs etc). So when a user is viewing the Telephone Directory Search page (Presentation Layer showing a table with a textbox and search button), they can search for an employee's number. On clicking "Submit", the BLL will be accessed, performing any business rules if required, then go to the Data Access Layer to get the queried information.

    4. I will create a seperate Data Access Layer website project. This will be made up of classes with the same idea as above (TelephoneDirectoryDAL.cs, ClassifiedsDAL.cs etc). When the business logic/rules are done in the BLL, it will call this DAL to add/update/select the required info as needed.

    Now, is the above 3 tier architecture looking correct? Have I gone with the correct approach here? Any suggestions/tips/advice? Many thanks!

    CH Wink


    Wednesday, April 21, 2010 3:43 AM

Answers

  • User-1366948256 posted

    Yes, Your idea is correct but there should be only one web application or website project in your solution. You should have bll and dal layer as class library.

    DAL will contains all the database related classes.

    BLL will contains all the bushiness logic classes and will call Dal classes for database operation. This project will have reference to the DAL Class library.

    Presentation layer will contain all the presentation logic to display data and all the data entry forms. This project will have only reference to BLL Class library and will no access DAL Directly it should access only via BLL project.

    So there should three separate will be there. Presentation,Business and Database layer.

    You can add more layers to it as per your convenience but there should be logical and physical separation between classes. 





    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 21, 2010 4:46 AM
  • User1334526469 posted

    Dear,

    If you go with having different Projects for Application, Business and DataAccess Layer then the architechture you mentioned is fine.

    But placing BL and DAL folder in App_Code folder have some advantages.

    Whenever you perform any change in BL or DAL, then you don't need to complile the  whole application. You just need to place the updated classes in App_Code folder. And it would automatically be compiled at run time (dynamically).

    But if you go with different BL and DAL projects then you need to compile the whole application when you add updated reference of BL or DAL.

    Suppose you changed only one class of BL then you just have to update that file in App_Code, not the whole project. It would be compiled dynamically. But in other case you have to build the whole application.

    Code within App_Code is shared within the application.

    But keep one thing in mind that, as code within App_Code folder is compiled dynamically so it may increase the response time for the first time access to that code (but just first time, not every time).


    ---------------------------------------

    Please mark this post as an answer, If This post helps you to solve your problem.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 21, 2010 4:57 AM

All replies

  • User-1366948256 posted

    Yes, Your idea is correct but there should be only one web application or website project in your solution. You should have bll and dal layer as class library.

    DAL will contains all the database related classes.

    BLL will contains all the bushiness logic classes and will call Dal classes for database operation. This project will have reference to the DAL Class library.

    Presentation layer will contain all the presentation logic to display data and all the data entry forms. This project will have only reference to BLL Class library and will no access DAL Directly it should access only via BLL project.

    So there should three separate will be there. Presentation,Business and Database layer.

    You can add more layers to it as per your convenience but there should be logical and physical separation between classes. 





    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 21, 2010 4:46 AM
  • User1334526469 posted

    Dear,

    If you go with having different Projects for Application, Business and DataAccess Layer then the architechture you mentioned is fine.

    But placing BL and DAL folder in App_Code folder have some advantages.

    Whenever you perform any change in BL or DAL, then you don't need to complile the  whole application. You just need to place the updated classes in App_Code folder. And it would automatically be compiled at run time (dynamically).

    But if you go with different BL and DAL projects then you need to compile the whole application when you add updated reference of BL or DAL.

    Suppose you changed only one class of BL then you just have to update that file in App_Code, not the whole project. It would be compiled dynamically. But in other case you have to build the whole application.

    Code within App_Code is shared within the application.

    But keep one thing in mind that, as code within App_Code folder is compiled dynamically so it may increase the response time for the first time access to that code (but just first time, not every time).


    ---------------------------------------

    Please mark this post as an answer, If This post helps you to solve your problem.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 21, 2010 4:57 AM
  • User515645503 posted

    Yes, Your idea is correct but there should be only one web application or website project in your solution. You should have bll and dal layer as class library.

    DAL will contains all the database related classes.

    BLL will contains all the bushiness logic classes and will call Dal classes for database operation. This project will have reference to the DAL Class library.

    Presentation layer will contain all the presentation logic to display data and all the data entry forms. This project will have only reference to BLL Class library and will no access DAL Directly it should access only via BLL project.

    So there should three separate will be there. Presentation,Business and Database layer.

    You can add more layers to it as per your convenience but there should be logical and physical separation between classes.


    Ok, thanks for the information. Considering the size of the Intranet Im going to be converting, would it not be better to have the BLL and DAL in seperate website projects? So having 3 website projects in total (including the Presentation level)? Im worried if I have one website project, and use class libraries for the BLL and DAL, the website project is going to be so "full" of files, maintaining it could become a task.

    Dear,

    If you go with having different Projects for Application, Business and DataAccess Layer then the architechture you mentioned is fine.

    But placing BL and DAL folder in App_Code folder have some advantages.

    Whenever you perform any change in BL or DAL, then you don't need to complile the  whole application. You just need to place the updated classes in App_Code folder. And it would automatically be compiled at run time (dynamically).

    But if you go with different BL and DAL projects then you need to compile the whole application when you add updated reference of BL or DAL.

    Suppose you changed only one class of BL then you just have to update that file in App_Code, not the whole project. It would be compiled dynamically. But in other case you have to build the whole application.

    Code within App_Code is shared within the application.

    But keep one thing in mind that, as code within App_Code folder is compiled dynamically so it may increase the response time for the first time access to that code (but just first time, not every time).


    Thanks for the info. Im going to be creating a website project and not a web application, so there should not need to be any compiling?

    Wednesday, April 21, 2010 5:44 AM
  • User1334526469 posted

    Dear,

    Then i think there is no big issue. You can carry on with your proposed architecture.

    Creating saperate projects and then referring its DLL doesn't have any issue, you can go for it.

    Good luck.


    ---------------------------------------

    Please mark this post as an answer, If This post helps you to solve your problem.

    Wednesday, April 21, 2010 6:26 AM
  • User515645503 posted

    Ok great, thanks for the guidance ;)

    Wednesday, April 21, 2010 7:57 AM
  • User1334526469 posted



    Wednesday, April 21, 2010 8:05 AM
  • User-952121411 posted

    would it not be better to have the BLL and DAL in separate website projects?
     

    Just to tag on to the end of this, I say "Yes."  For (2) reasons:  1st if the layer begins to grow and have several files (as it will), it is just plain cleaner in VS.NET to have each logical layer in its own project.  Then you can have the .dll built from that project referenced as needed with no problems.  2nd, for scalability possibilities, if you ever needed to port out one of your layers to a service you would be ahead of the game and not need to surgically unbolt the code that sat so close to your UI as it would be if it were in the 'App_Code' folder. 

    Im going to be creating a website project and not a web application, so there should not need to be any compiling?

    Good move on the web application project.  Yes you do "Build" or compile your site and the resulting binaries are deployed to the server along with the pages, etc.  This is in contrast to a web site project where all of the files (including source code) is deployed to the server and compiled at runtime.

    Friday, April 23, 2010 4:04 PM