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 layersRight 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
- 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.
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