The main purpose of "Dot Net Labs" provide the dot net program. You can learn dot net, .Net Core, C#, SQL, Linq step-by-step.

Thursday 18 May 2023

Create .Net 6 Web API project with Three Tier Architecture - Part 1


Introduction

We will see three tier architecture and how to create the Business Access Layer and Data Access Layer in our project, as well as how to add references between the project.

Project Structure

Here we are going to use three-tier architecture, with a business access layer, a data access layer, and an application presentation layer, see the below diagram how to interact layers.

Let's discuss these layers

Presentation Layer:

In short, called PL. This layer is the top layer of the three-tier architecture. The main responsible for the user interface and user interaction. It handles user input and display information to the user.

Business Access Layer:

In short, called BAL, Contains the core business logic and set rules of the application, handles the processing, manipulation of data, and validates and enforces business rules and constraints. Typically includes classes and methods that represent business entities, services, and workflows.

Data Access Layer:

In short, called DAL, Encapsulates database queries and CRUD (Create, Read, Update, Delete) operations. It is responsible for accessing and manipulating data from various data sources like database, web services. DAL utilizes technologies such as ADO.NET, Entity Framework, or an Object-Relational Mapping(ORM) framework.

Configuring Layers

Right click on the project and go to the new project window and then add .net core class liabray project.

Add the class Liabrary project for Data Access Layer and Business Access Layer.


Add References

In the Presentation Layer,  add the references to the Data Access Layer and the Business Access Layer.

Right click on the presentation layer and then click on Add then go to Project Reference


Add the references by check to all checkboxes


Now we will add the Data Access Layer project references to the Business Layer.

Same right click on the business access layer and then click Add button > Project References


Remember

  • Data Access Layer's main goal is to interface with the database and the business layer.
  • DAL can have the following folders as per your requirement.
    • Contacts
      • We define the interface that has the function that performs the desired functionalities with the database.
    • Data
      • We have Db Context class which is very important for accessing the data from the database.
    • Migrations
      • The migration folder contains information on all the migrations we performed during the construction of the project. 
    • Models
      • This folder contains domain-specific data, and business logic models, which represent the structure of the data as public attributes, business logic, and methods.
    • Repositories
      • We add repository classes against each model and write the CRUD function that communicates with the database using the entity framework.
  • Business layer can have extensions methods and services folder that make the logical decision and evaluations the main function is to process the data between surrounding layers.
  • Presentation layer present the data that we get from the business access layer and give the results to the front-end user.
Advantages of 3-Tier Architecture

The three-tier architecure offers several advantages that easy to the development and maintenance of robust and scalable applications. Below are some key benefits of using a three-tier architecture.

Separation of Concerns: The architecture separates the application into distinct layers, with each layer having its own set of responsibilities. It enhances code reusability, maintainability, and makes it easier to update or modify individual layers without affecting the others.

Scalability: Three-tier architecture enables horizontal scalability by allowing each layer to be scaled independently. For example, if the application experiences increased traffic or data load, you can add more servers to the presentation or business logic layer without affecting the data access layer. This scalability is crucial for handling growing user demands and ensuring optimal performance.

Flexibility and Adaptability: The clear separation of layers in the architecture facilitates flexibility and adaptability. Each layer can be developed using different technologies, frameworks, or platforms as long as they can communicate with each other through well-defined interfaces. This enables the use of specialized tools or technologies for specific layers, making it easier to incorporate new technologies or update existing ones without impacting the entire application.

Improved Security: By separating the layers, the architecture can enhance security. The data access layer can implement security measures like encryption, parameterized queries, and access control to protect against malicious attacks. The business logic layer can enforce security rules and validation to ensure the integrity of data and prevent unauthorized access. Separating the layers also minimizes the exposure of sensitive information in the presentation layer.

Testability and Maintainability: The three-tier architecture promotes testability and maintainability. Each layer can be independently tested, allowing for more focused and comprehensive testing. It simplifies unit testing, integration testing, and regression testing, as changes in one layer are less likely to affect other layers. Additionally, the separation of concerns makes it easier to identify and fix issues or make updates without impacting the entire application.

Team Collaboration: The architecture supports team collaboration by providing clear boundaries between different layers. Different teams or developers can work concurrently on different layers, making it easier to divide the workload and foster collaboration. It also promotes modular development practices, allowing teams to work on specific layers without disrupting others.

Thanks

0 comments:

Post a Comment

Do not enter spam link

Popular Posts