Three Tier Architecture Example in ASP.NET CORE

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome my channel asp.net core and today I'm going to teach you what is the three Tire architecture and with example you know so uh three Tire architecture is actually consists of you know that uh three layers presentation layer business logic layer and data access layer the presentation layer handles the user interface the business layer layer contains the application logic and the data access layer is responsible for interacting with the database okay so this architecture is easy to maintain and uh test but it can become complex as the application draws you know so uh first of all you know that uh that is the first of all design the presentation layer then after you can go for that access layer and then after you can go for the business logic layer so uh first of all just I am going to tell you about that access layer okay so what inside that access layer actually actually data access layer is directly communicated with the database so in the data access layer we will use a model I am going to use uh application DB context and that is the report and then after we can use Repository so the third layer is first of all just I am going to discuss that is business logic layer and uh okay so just I am going to describe first of all about dot access layer okay so let's discuss this layer handles the data access and database operations it should be independent of the presentation layer and the business logic layer for uh you can see so uh in the data access layer first of all just I am going to design models okay so just right click on the data access layer first of all and add three folders in the data access layer okay so foreign and you know that at the first folder is the entities that second folder is the data and the third folder is that is interface okay so uh you know that in the data layer this layer is responsible for handling the storage and retrieval it should be responsible for performing crud create read update and delete operation on the data and should encapsulate that data Logic the data layer can be implemented using Entity framework Dapper or any other data access technology it should expose interfaces or repositories that the application layer can use to access the data okay so here we have an example so first of all design entity here I am going to add only the customer entity Okay so this is very pretty simple techniques to design a project using the three Tire architecture okay so okay so here I am going to add a new context class that is application DB context class under the data section so so here I am going to use application DB context directly in the data access layer but there is a lots of pattern there is lots of techniques to use a data access layer actually so you know that a data layer is responsible for handling data storage and retrieval so the data layer can be implemented using various Technologies such as Entity framework Dapper or radio.net here are some common patterns used in the data layer first one is a repository a pattern that I am using here so this pattern is used to abstract the data access layer from that rest of the application by providing a set of interfaces for accessing data it provided way to perform credit operation on the data and Abstract away the implementation detail of the underlying data storage technology this makes it easier to change the data storage technology without affecting the rest of the application so that is the repository pattern that I am using in the uh in the data access layer okay so first of all you know that entity is clear so customer uh we have and in the data uh directory we have a application DB context so this time going to design application DB context that is zoom claim uh in header from the DB context class and now uh adding a customer class in the in that class okay so the next one is to add I customer repository okay so uh that is the repository pattern that I'm using Okay so the next one pattern you can use it here as a data access layer that is the unit of work pattern this pattern is used to manage the transactional transactional boundaries of a set of related operations it ensured that all operations are either committed or rolled back as a single unit of work the unit of work pattern is commonly used to conjunction with the repository pattern okay so that is the second method to use it so by using the repository and unit of work pattern the data layer is abstracted away from the rest of the application making it easier to change the data storage technology without affecting the rest of application additionally these patterns make it easier to test the data layer in isolated without requiring to leave a data based connections okay so this is the technique so here I am using only repository pattern okay and only one methods in this I am going to tell you that is the data that is the get customer answer okay that's fine that is very pretty simple way to design it so everything is clear about the data access layer now just go for the business logic layer actually business logic layer is implemented from the data access layer okay so now tell me more about uh you can say that uh business layer okay so a business layer or you can say that this lady sits between the presentation layer and the data layer this is responsible for handling business Logics and Performing operations on the data it should uh contain all the necessary logic to manipulate the data and perform an in any necessary validations the goal of this layer is to make it easy to change the underlying better layer without affecting the presentation layer typically the application layer consists of servicing services that interact with the data layer through repositories these Services should be independent of the Interlink data storage technology and should be testable in the isolation some common pattern used in the application layer include the service layer pattern or the command query responsible segregation pattern that is the SQL sweater that's I am using in the business logic layer so you know that that about the business logic layer okay so uh here I'm using customer services I customer service and customer service here I'm using I customer repository to implement the customer services okay so if you know if you want to know about and more about the uh this layer service layer you can say that this pattern you used to encapsulate the application logic and the provided a single entry point for the presentation layer to interact with the data layer it provides a set of services that can be used to perform operations on the data such as credit operation or the business logic operations so this time I'm going to use it here and if you want to know about the command query responsibility segregation in that layer that is the business logic layer this pattern is used to separate the command that is the right operations from the query that is the read operations it provides separate models and handles for handling commands and queries respectively these patterns can be used for optimizing read heavy applications okay so that's fine I I think it is very enough to explain about the business logic layer the next one is the presentation layer you know that the customer controller is now I'm using and you know that actually business logic layer sits between the presentation layer and uh and uh my data access layer so here I'm using a service layer or you can say that a business logic layer now uh the next one you know that a presentation layer and if you know about more about so finally we will go for the next uh that is the design a view for the index section method that is the intersection method where I am I'm going to design a list of customers that I am going to add okay so uh if you know more about the presentation layer actually presentation layer is uh we know that if you know about the presentation layer uh you know that presentation layer is responsible for handling the user interface and user input and output it should be kept as thin as possible and should not contain any business logic the goal of this layer is to Simply display the data and provide a way for the user to interact with the application some common Technologies used in the presentation layer of an application core application include Razer Pages MVC and Blazer so that is the mean of the presentation layer so here I am going to add Scaffolding in this index section method to design this okay now the next one is to go for the migration as well and the next one is to add dependency injection so what uh actually asp.net core provide built-in dependence injection you know that so if you know about dependency injection so our dependency injection is a design pattern used in software engineering to implement inversion of control in application it is technique where the dependencies open object are injected from outside the object rather than having the object created themselves itself asp.net core application di is used to manage object dependencies and provide instances of these object to the application component that require them the DI container is responsible for creating instance of object and injecting their dependencies in as a scoped okay so here I am using scoped right here and here we have two dependencies that is the I customer service and I customer repository so first of all I customer repository is used so according to the top-down approach this I am going to add I customer repository first and then use I customer service and that interfaces are actually implemented by these classes that is customer repository and the customer service okay everything is now now the next one is to uh Implement a connection string and if you know that uh so uh just I'm going to tell you about application DB context class actually why I am registering here I application DB context right here so application DB context class is a class in Entity framework core that is used to represent a session with a database it it is a subclass of the DB context class which provide a high level API for interacting with the database in an object oriented way the application DB context class is typically defined in the data layer of an asp.net core application it is and it inherits from DB context it contains a DB set property for each entity in the database which allow us to perform crud that is the create read update and delete operation on the entities okay so everything is clear now the next one is to add DB context with the SQL Server okay so uh if you want to know that uh to add an instance of the DB context with the SQL Server you first need to install the necessary packages you will need to install the Microsoft dot Entity framework code or SQL server and Microsoft dot entity framework.tools actually SQL Server provided the interface to create a database by using the SQL Server okay and the tools package is actually responsible for migrations okay so uh once we have installed these required packages you add to instance of TV context with the SQL Server by following these steps these are you can see in this video so define a class that inherits from the DB context class and provide a DD set property of the each entity in the database that is already existing in that access layer you know that so after you want to configure that DB context class in the program.cs file so in the configure service method of your start audio of your program.cs file or a class you need to configure your DB card text class to use SQL Server here is an example you can see okay so actually use SQL Server is a method so if you if you know that U SQL server is not exist I mean to say that if you have a installed package SQL server but you are not actually resolve this types of problem because actually I want to register DB contest instead of the dependency injection so here you can see that ad is formed now here I am using add DB context instead of add scoped so that you can see okay so that is the three Tire architecture uh and if you know more about the three Tire architecture you can ask me by the comment and uh which uh architecture is the best architecture for your application just I am going to suggest you if you comment me and I will Design the old remaining applications one by one I uh I'm too much excited to design a school project uh please students carefully listen me please see uh please watch all the videos of the school management system because that is the ARP project and if you are the Malone if you want to design a monolithic architecture then you can see inventory project because that's project is actually built on monolithic architecture so everything inside in the you can say that everything inside it in a single application so that is the theater architecture where you can see business layer presentation layer and the data access layer everything you know that so thank you guys for watching this video and keep watching all other videos which is selected to asp.net core and please watch this full video because the remaining whole video video session because you know that add a migration initial that is the migration process after migration you have to update the database and then after you can see uh lots of steps you have okay like uh you know that uh wonderful steps you you will know that that is the migration steps and build the database and uh if you want uh you uh then linking in the layout.cssd1 file and then after the run your projects so thank you guys for watching and please don't forget please subscribe my channel and also press the Bell icon to get the latest notification about uh and income coming soon videos okay thank you very much
Info
Channel: ASP.NET MVC
Views: 16,313
Rating: undefined out of 5
Keywords:
Id: Zpq21ErM4ZA
Channel Id: undefined
Length: 20min 16sec (1216 seconds)
Published: Mon Apr 03 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.