Clean architecture in asp.net core web api | CQRS | Mediator

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I already create a clean architecture connection with sequence pattern and along with mediator R so this is a our user interface is API okay and I already created that you know um that get posts you know put delete endpoint in our API uh user interface okay so we'll see first let's see the you know output how is working it is the similar kind of things okay let's execute first okay see there's a no data because as of now uh my blog is empty so that's why it's empty so let's collapse and then let's add you know some data over here then then add some blocks so that I can able to see the data okay let's try and just add on a C sharp first block my SSC shop and then it is a C sharp is a C sharp is so is a good language or popular language actually PNG like that okay and then just execute and see the output see output is there like generate ID is three and the name is this and this this 2000 zero two zero one is uh you know the response output we have get it okay and let me check like whatever we have you know insert it you know add a new blog so that is that is there or not okay that execute C I added one block so I can get one so let me try one more like change it to C sharp to like you know angular and then angular it's also like angular is a good angular is a client site app or popular client-side app also unlike kkp is this uh this should be change of angular okay and let's okay let's execute see it is two zero one and generated is 4 and it is angular and this this and so let me check for the get all the blocks endpoint call the get all done once and see there's a 3 and 4 is there okay and the other end points as well we have you know created over here like in a card application like we can get yid based on the ID also right okay so let me try the title like suppose for example one okay the block one I want to want see there's a four zero one that means I don't have any idea of ones okay so let me try three because we have exist three so see three is there if I change to three to four so definitely you will get that four okay and then similar to we want to update some ID in some data okay in this block so how we can achieve very simple like same things if I want to update like three so just put a three and then change it to three and then I want to three was you know C sharp so why I want to change C sharp to like you know clean architecture okay so like this is a Blog of killing architecture so clean architecture and this is uh nice blog like for example and this is also kkp and then it is a clean architects.png okay and then let me execute C two zero four that means it's success and let me verify it like whatever things we have update it is update or not let me get it all the blog see I change it it was previously was C sharp so I change it to you know clean architecture and those all the property also updated and there's another endpoint is for the delete okay so I want to delete like ID3 just execute it like three is deleted let me check one more time for all the get blocks see three is gone only remaining is four and that is for the demo over here okay and in this session actually uh actually in this series uh we'll create you know many too many things like you know how we can create a architecture how we'll create you know uh I will create architecture and how we'll uh set up that architecture and how how what are the prerequisition over there what is the you know packages required so those will be like include and as well as you know one by one every you know layer like this is a you know if if I talk about clean architecture so already it is enough four layer like you know infrastructure layer domain layer application layer and then UI layer so every layer will Implement one by one in next upcoming City upcoming I know upcoming uh series okay so this is overview and we'll talk about also you know uh something like what is screen action I'll give I also brief and today introductions on this cleaner connection and everything in our basic one if you go to my channel so definitely you will get those one but yeah I'll again I create another one this is the advanced level so definitely I'll explain a little little bit for this you know like killing what is the clean architecture you know again architecture approach an architecture approach that emphasis separation of the concern and dependency inversion it's consisting of the separate layers and with the clear clear responsibility you know for example see over here like if we talk about the presentation layer so CCC this is presentation layer and this presentation layer actually handle user interactions UI components API controllers okay and then we if I talk about application layer so application layer contain actually application layer contain application specific business logic so all the business logic will include over here okay don't worry about that I include also a secure s pattern over here so we'll we'll explain in detail as well so move it to next what is that domain layer contain actually the domain layer represent the core business domain models and rules okay so all the domains and models you know over here in this the domain layer okay and then finally we have you know that infrastructure layer and the infrastructure layer provide implementation of the external concern like database apis and external Services those are things we have involved so these are a clean architecture okay about little bit Millions so now I'll I will give the some overview about the sequence pattern okay so like see this is a sequence pattern we'll use you know command query extra okay so uh secure SQL what is the SQL respect and the sequence pattern is the read and write operation in an application optimize ease of every the every each for their specific needs it's introduced to diff distance pattern actually like one of the command okay and the second one is a query so in this command uh command represent the operation that change the state of the system for example create delete update okay such kind of things let's see if I more explain so you will able to see so don't worry about that I will create from scratch in my next upcoming video okay and if I talk about that queries okay now next one is a query so query represent operation that retrieved the data from system without any modification so like that like I'll get the data you know like get blogs and get blocked by ID you know without modifying the data okay and also in this layer actually we'll we'll put some you know common things like you know like validations and also will handle the mapping things so don't worry I'll go with the details in the later okay now in this architecture actually we'll use like okay we we use Securus pattern and also we we have used in the mediator pattern so what is that actually so let me open that like open the user interface like API layer and if you go to block control in a block controller so you will see that you know mediator pattern so what is mediator pattern actually okay let me Zoom it I think you are not able to let me Zoom it yes okay so see like mediator pattern called directly in an application layer and now get the data okay and same behavior for you know I insert update delete everything you know so what is that mediator pattern so mediator the mediator pattern is a facilities communication between different between different components of an application without them having direct dependency on the each other it's promotes Loosely coupling by introduce a mediator component responsible for coordinate the interaction okay so these all are over the view overview of that you know cleaner security pattern and uh what's called what's a and yeah mediator button and also you know I will use IMAP and etc etc so in the next video will create you know all the project setup how we can set up a project okay infrastructure setup will create it in next upcoming video and then one by one we'll Implement you know uh that uh every layer okay so let me open the visual studio okay and here you need to just create a new project okay uh let me search web API in this series I'll I will take a web API web API you know template you know for my user interface but yeah we when later on in the another series definitely I show you like how we can use this clean architecture you know many another template like for example MBC application or or other other UI interface okay so let me create esp.net core web application application actually we required web API so you have to use this one let me zoom in for you okay see this is a template we are actually we mentioned in sp.net core web API along with C sharp so definitely before creating definitely you have to check out like okay what is actually we are choosing like C sharp or F shars whatever uh languages we have chosen okay so next okay here we have specify the name okay let me put some name okay clean clean architecture okay I'll put the short name green architecture with you know RC QRS pattern cqrs and and made it error theater R okay mediator and it is uh project name is a API so let's call is the API but yeah this is a solution name I don't want to use the solution name also okay because solution name should be as a unique okay and then layer wise you can just put your project name okay let's create a next okay here just you can use simply like configuration State whatever the default things you can just use it okay and one more thing don't you stop level statement so yeah you can just keep it whatever over here and click next our solution has created and along with we have created you know that presentation layer Okay so that is fine also if I don't I will not go over you know details of this web API project solution because I already explained everything if you first time creating web API project so definitely I'll recommend to you go to my channel and you can watch my previous previous or you know that session okay okay that is fine then what I need to do I need to now what I need to create I need to create another Library actually new project or the solution way so you have to click the solution and add a new new project okay and then add a library I have over here because I last time I chose this over here but yeah if you first time so definitely you have to check like you know class Library class library and again you have to make sure like this is a class library but make sure like what the languages you are choosing like C sharp app shares or what okay so I just choose like simply class Library which is actually you know supported.net and Dot net standard so that is fine for us just click go next and then we have to put some name okay for example whatever our solution name so this is our solution name and then this is a domain layer so just put the domain domain okay and next and choose Target framework so as of now is a standard team supportive sports.net 7 so I will just choose I have a preview 8 but yeah I'll choose the seven because this is a stable version so okay and in this domain layer actually what need to contain here need to contain actually The Entity and the repository okay so let me add the folder only just I'll just create a setup I will not implementation anything just create a setup so what are the content over here so I'll just put over here so entity will in DT okay entity folder and another one is like Repository okay depository okay so yeah now this is done and that is sufficient for here just remove this class one okay and then move it to another one now required another one is an application layer so let me again add another project similar class Library you can search over here or directly over here next now same name of the solution name and Dot we can post we can post over here like application I everything I actually explain in overviews session in previous session so if you first time so definitely I recommend to you go to and go to visit my channel and watch my previous session application okay application and then next choose the.net system work that is done okay remove that you know by default generated class okay and here what I need to what are the the folder structure I required over here actually we use a clean architecture so definitely we required you know some command query uh stuff okay so let me add actually we'll uh in this series we'll take an example of blocks okay so let me create uh blogs okay blogs folders okay in this blocks folder we have to what need to do in this blocks folder actually we have to insert update delete you know card operations okay so what are the you know things we have to do over here under the blocks okay so I need to create a command okay because it's a secure as button we are using so definitely there's a two distincts and uh things we required so first is enough commands okay don't worry about that what is command what is query I later when will implementation you know that application layer I'll explain everything again but yeah I'll give in some overview so you can you can visit you can visit my channel and go to check my previous session video okay and then under this command what are the what are you know what we have to maintain in this command so we have to maintain like create blog okay create blog and then update block update blog and similar you know delete block as of now this is sufficient but later on we'll discuss and will record I will add more okay so this is the standard actually then command as complete then we have to require that queries okay so queries okay under this queries actually what we'll achieve under this query we have to okay let me commands and query okay so let me add another folder inside the queries you know get blocks okay they'll get blocks and get blogs ID as well get blogs blog by ID okay so this is done okay for that sequence pattern like we will handle in this blocks like create update delete and as well as in a query part we'll end it get blocks by ID and get blocks okay and there are you know some you know in this layer actually we have to add one more folder you know that is called is a common so that whatever common logic whatever command service okay common sorry not command common okay so in this common actually will handle like validations okay like validation exceptions and mapping as well okay so let me add let me act like behavioral okay whatever behavioral things we will we will we have to keep under this folder okay behaviors okay under this Behavior actually we'll we'll add you know some validations and Etc and also we'll add some you know what call is look like like if we want to handle some exception so that should be under in the application layer and we'll use it under this command okay so I exceptions also we can keep it to exception exceptions okay and also mapping so these three three things is common but later on we'll add more once we required anything okay so mappings idea is common folder in the application layer we have to use so that we can use the all over the application which is the commonly we use like for example validation so validation is the commonly used so we'll put over here we can register as well okay so this is done and then finally we have to create one configuration things okay okay one thing I miss I guess so one dependency okay I I okay I forget that ones like C I created uh the domain layer but I forget you know adding the dependency what are the dependency required so in this domain layer actually required one more dependency like you know mediator R packages so we'll add that one don't worry so first let me add let me add some configuration so every layer like so this is application layer so I need to register some you know resistor registering dependency over here so that's why we have to create one configuration service okay so how can do that just create add new class and create it to configuration service okay call it to configuration service dot CS file see this is the configuration engine make it to public and also we have to use a static okay and then okay now create a method okay we'll create a some extension button we look we have to create this you know Services extension method so that this call to our UI interface okay so public static and then I need to I service provider I service not all server I need twice service collection my service collection okay which is coming from I think yeah Microsoft extension dependency okay that need to add so yeah so now first we have to add some packages okay before adding this service so what are the package dependency required so let me add first in the domain layer in the domain layer just go to manage packages okay and here we have to add you know that mediator R so let me add let me search that mediator r okay why are you adding in the meditator and the domain because this mediator are you know using somehow over here and also somehow they you know for UI layer so that's why I call it to here but yeah we can use that military application layer as well so it is not a very big big impact but yeah that is fine for here because Microsoft Microsoft teams are using in this place so definitely that's why I am using simplest okay so I use mediterrer for this version because this is our latest version so add this one apply okay so yeah now it is installed if you see over here okay see it is green tick that means this is tall and also it's saying update and uninstall okay so it is done mediter has done then I need to install in application layer so what are the prerequisition on that I already discussed but yeah I'll I required you know that mediator are you know automaper sorry the automaper mediator are already installed but yeah then another things is automaper extension actually that automaper extension contain that you know service collection class as well so that's why I need to add nuget package like Auto map or extension okay so let me search this automaper extension yes you see this is automaper extension but I need automaper extension Microsoft dependency automaper extension Microsoft dependency let me choose let me search okay let me search this one yeah so I'm looking this one like Auto map extension Microsoft extension so if you okay so this one actually uh dependence injection okay so in this here actually there is a lot of dependency so it is include that uh abstract dependency as well so let me install this one apply okay so this is existing error don't worry about that okay and one more thing actually we have to use okay one more package is required like in this application layer that is called flu ENT validations dependency section so let me add that one also so don't worry about that let me set up but when we'll Implement then I'll explain why it's required okay so this is another package okay if you fluent validation dot dependent dependency injection extension okay let me add this is mainly purpose for you know validation our uh command and query whatever before reaching the command and query we have to validate actually so yeah this package will help for that okay so see this is also installed if you double click over here you will see these two packages installed over here also one more thing we have to add this domain layer actually dependent the application layer so let me add the domain layer over here so project dependency let me add the domain layer okay okay see so three dependency over here an application layer okay uh one is that you know domain layer domain layer and another two is like you know automaper extension and dependency on this one let me zoom in so that you will able to see that dependency what are the dependencies this is first this is second and this is third one okay so this is third one in the domain layer okay so this is fine for as of now and now move it to here let me create a service collection and then bring the name SPC using bring the name Express it is meaning over here because I adding those packages that's why and and then I need to add you know some extension name like what is the extension name it is called like something add application you know application services and see I need to use this this I collection service because it's extension so that every extension when we use over here so it will automatically show me that things okay and here we have to resolve some dependency like service dot add okay we have to resolve this one we have to resistor actually and assembly also assume only I need to bring the name Special Assembly yeah it is the under the system the reflection so assembly dot get execute assembly okay so all the assembly will execute and register over here okay for the auto mapper extension one is this and then another one is service dot add okay no not like that okay later on we'll add because there's a many things we have to add but once we you know try to implement so that time will add an show you why we record that one okay but as of now uh for the setup purpose I think this is required so that's why I'm adding you adding over here and one more thing like Services dot add mediator are map mediator R actually so that also required C and under this Lambda expression we have to CFG okay and register to registered register service for assembly actually we have two register service from assembly okay this guy and that's it okay and that's it and just return Services okay so this is done okay so application layer also done now we have to move to that another one like infrastructure layer okay so let me create another Library add project similar kind of fashion like if you choose if appearing over there you can choose over here neither you can just click and search over here then I will choose over here because I have already there so same similar kind of Fashions we'll follow and this is infrastructure okay infra I call it just infra I think that is fine infra and then next create okay remove that my default class and in this infrastructure we will contain actually that you know database things and also repository so that our AP you know our application layer actually direct will not connect Direct in the API in the database directly we'll call the repository and repositive will interact the you know the database okay so for this what are required and like first is required in our data and in this data will contain you know about DB context all of the things we will continue over here and also another one we'll call it Repository repository actually here actually in the infrastructure layer will a will implementation this is the implementation layer outside outer implementation layer actually so Repose tree the PO Z3 okay so Repository and in this repository actually will Implement whatever you know our rules and repository over here like you know for example I'll create a one repository for connectivity the database so interface will be there and you know implementation over here so whatever implementation it will directly connect with this you know uh the context you know database directly interactively here and then only application layer in a talk with the and in here also we have to we have to create that you know resistor dependency so that whatever dependency in this layer we have to resolve and fix it okay so yeah let me add a class similar type of class okay that's called a configuration service okay but this configuration service for the infrastructure layer okay and similar public okay and yeah one more thing I'm missing again like see this infrastructure layer actually depending the you know domain layer and application layer but already domain layer you know let me Zoom it so that you can understand very well okay so see in infrastructure layer dependent in the domain layer in domain layer and the application layer okay so I already domain layer you know dependent I add the reference on application layer so application layer have you know have the domain layer dependent cell I see if you open C the application there also have a domain layer dependency okay so what I need to do I just need to add only this two here so that I can have access on both okay when you add that application layer so if you go to c c i have application layer access and as well as like you know domain layer as well as all the dependency here like this in this dependency menu automaper and fluent API everything I have okay so those dependency has been resolved okay now need to implementation over here like same public static class and then I need to create a okay let me small it okay let me minimize okay public then static and then I service collection I service collection okay and let me add some meaningful name so that actually what we are doing I am doing just add infrastructure dependency services so let me add this guy and then this and also here we record one more thing actually we required some you know configuration part over here because I know I have to resolve dependence you know some database things so in database things in database configuration we'll have to come in the in the you know UI layer and then those UI layer will get that configuration so yeah so so let me add another property what we are passing over here that configuration so where I will get that configuration I configuration V integration okay oh sorry I configuration and then make it name same as a configuration and let me bring the name space and uh it is like configuration I guess let me okay so it is iconfigation yeah uh it is required I think Microsoft extension configuration abstraction so let me add this one just install okay let me install and it is adding over here let this done okay this is done okay and later on and so we have to return the service okay that's it okay so this also done except whatever you know connection and things will register over here but yeah we have to resolve the dependency over here that's why I call over here okay these are all the setup done for that you know domain infrastructure and here so we'll see in the infrastructure layer just add you know these packages and also like you know that uh dependence your application layer okay and finally in the in a in a UI layer okay in UI layer we have to record one dependency of application layer so how we can add that just simply add the reference and add application layer okay and that's it okay see the application layer have the domain layer and those domain layer that's it okay so that is fine uh I think in application layer okay sorry I think these two things actually required that application layer and infrastructure list so two dependency required so let me add another one that is fine and infrastructure layer okay so yeah that the two dependency required in this UI layer the application and infrastructure so I add it over here so now it is done and what I need to do I just add whatever you know that you know layer wise service dependency I need to register over here you know I need to call it over here so how we can do that simple Builder dot services Dot whatever the name just call out over here I whatever I created the name I create a add application service so go back to here just add over here just put the name okay and the bring the name space so let me bring the name space I think there's some issue directly uh you know directly not we are getting those uh name space so what I can do I just adding some namespace like using uh clean architecture with the mediator R and then it is a coming from application layer so let me add that application layer okay so see this is resolve okay if you right click and go to definition so definitely will reach in the application layer in implementation okay now go back again just save it again similar things what need to do uh we have to add registration on this one uh infrastructure layer okay so I have another extension method Builder Services dot add that call is I forget the name but yeah we can copy it from here the name is ADD infrastructure dependency so go back here just paste it over here okay and again the name bring the name is first directly it should not happen so don't worry about that you can just using clean architecture whatever the our project name and then what is the this this one so see once I bring as automatically changed to color and see it is asking to eye configuration so where I will get that icon vacation I will get if conversion under this Builder Dot configuration okay so Builder dot configuration that's it so we can add something like add layers deep and then see okay so that's it now just build one more time see will succeed okay there's no error so that our project setup successfully built and also the setup is completed okay so these you know this is the way very easy nice or easiest way so that we can exist you know create our you know whatever package is required we can add and also set up that you know project is Project structure okay so this is a clean architecture okay and also uh we adding that all the required packages so in next video we'll Implement one by one like first we'll Implement you know the domain layer in domain layer I'll adding some entities and then whatever you know uh the rules we have we need to add will add an Implement and we'll discuss as well what is the domain layer one by one and then we'll add an application layer and how we'll create you know that create command delete command update command and how we can get that queries get by queries get by queries and also how we can add that you know Common uh some validators and mappings things okay as well as whatever required dependence we'll have to resolve as well here okay and then another session we'll discuss implementation about the infrastructure layer okay and here also We'll add some you know DB context and then we'll Implement and connectivity.db how we can connect this is the same example whatever we have in last session okay we have actually created us project setup we have a user interface layer we have an application layer and we have a domain layer and we have also an infrastructure layer okay so in this session we'll Implement how we can Implement over here okay so just give a little bit idea okay because I if you first time came over here so what is domain layer actually so domain layer actually represent the core business domain models and rules Okay so so let's get started to implement how we can do that so already you will see I already create an entity folder and also in a repository folder okay so let's get started so first we have to create you know uh one entity over here so as of now I already shown in a demo in my first series first session like we actually creating a bear creating an endpoint in a blog endpoint where I can you know create update delete you know I can do a curd operation on the on the Block so first I need to create entity blocks okay so how we can key how we can do that right click on the entity add add a class and just create a blogs okay let me create a blogs okay and just make it public so that I can access in the another layer okay and just create a some property over here okay already it is see me you know example like it should be have a ID name and then descriptions and then also created data Etc whatever we want but for the for a demo perspective I just created I think just you know not this one but yeah I just change it to author okay so let me change it to the end and change it to author okay okay that's it let me format it control KD okay okay so see entity has created which actually represent our whatever entities in our domain layer okay and then we have to create a one repository okay so that whatever repository will I'll call to you know application there and then application layer interact uh with the you know API layer and so that they don't about know that what is the you know implementation and implementation would be in the infrastructure so don't worry about that we'll do uh session by session and step by step so every layers so in this session we'll cover on the domain layer and next session will cover in application layer and then next session will cover in the infrastructure layer okay so uh let me create a repository so what what performance what you know operation need to do so let me create a repository for that let me create a interface for that so that it's abstract and let me name it you know I blog my blog Repository I block repository okay that's it and make also it's a public and whatever operation we have to perform about the blocks so we have to create that thing so let me create a task so that it is could be a async method you know is synchronized so let me create a list so that I can return a list of the blocks over here so let me bring the entity over here let me bring the name space block so see which whatever we created so let me bring the name space and let me get all get all blocks okay and async async okay that's it like that we have to implement like you know get all blocks get get blocked by ID you know create blog update blog delete blog so such kind of things we have to implement okay uh instead of wasting time just you know just to copy and paste okay see I create you know similar like first list of blocks okay and then list only just single blocks by the ID of the block ID and then create block and update block and delete block okay so that is done for the implementation perspective for the domain layer okay so I think yeah that is then also if you don't know how we can create a setup so definitely May comment to watch my first video uh my previous session and see all already we have adding a mediator packages so that we can you know coordinate in our Apple user interface to you know our application layer we have you know implementation domain layer but yeah we have to implement you know this application layer and in this application layer actually we have already created a command and query which is part of Securus pattern okay so we follow actually in the sequence pattern like command and query so in this session we'll cover first you know get blocks query okay let me zoom in okay so yeah in this in this session we'll cover in this getable oxide get blocks all the get blocks then we'll cover next session is get blocks ID then we'll create a create blogs delete blocks and update blocks okay so we'll cover one by one so that we can easily understand and digest okay so okay let's get started let me add first a class okay that is called as a view model so whatever you know application layer returning the data actually convert the data of entity from The Entity domain entity so we have to convert in a domain view model okay so that view model will be able to create first so let me call it to blog BM okay and let me create some property so that whatever we have want to return we can create it okay so just create okay and uh okay I guess I don't think we have to return that image URL okay so yeah that is fine for this demo purpose okay then we have to create a query class okay so how we can do that let me create a get blog query okay and make it to public and just inherit I request I request interface okay see it is a inside of that mediator inside of the mediator interface okay so let's call it and see what need to pass up this year we have to pass you know a response so what could be our response uh we we have to return this much as a list list of blog view model okay which is just created okay okay this is a one way there is another way actually uh I think yeah there's another way we can do that I think instead of class we can use a record okay this is a new way actually so in this record we don't record this okay like this way see and just do that okay so yeah there is a two way actually create a query class uh the old-fashioned is the class and the new version is a record okay so yeah I'll move it to you know that old one also just for knowledge purpose I just share you okay okay and then what need to create see we have create a query class so in this query class we have to implement as a one Handler okay so how we can do that in this sequence pattern so let me create get blog query Handler okay and then make it to public and just inherit I request Handler okay so that we can pass it and we can you know handle you know whatever our request what is our response okay that's why we create this Handler and what is our request our request is get blog query which is just created here okay so this one actually our request so pass it to here and then what is the response our response is just list of block view model okay so yeah that is done and then why is complaining because it is complaining it is an interface so we have to implement the method as well okay whatever Implement in this interface okay so once you Mouse over over here then you will see this see that in a bloop sign and also once you click over here just share the option of implement interface so you can just Implement okay and let me just drag there okay so now see this is a Handler class Handler method is generated okay there's a by default it's you know just not Implement exception is a throw in over here Implement so we have to remove and we'll do our our things okay okay now now how we can get the data okay in this Handler so in this Handler we will get the data from our domain layer okay so see in this domain layer we already Implement is a you know one abstraction repository okay power block blocks abstraction okay so we have to inject this one and over here in this Handler and then we have to call those method okay so see direct I have create control uh you know Constructor of this Handler class and what I need to do I just inject this block repository and then control dot so it will show me the we have to assign up as a field okay so just assign this you know inject and assign is create the instance of that okay of the block repository and then we can use easily and now we can use that just okay just create a weight because it is a single method so we have to add a weight and then whatever our you know create instance property okay reading the property is a Blog repository and inside the blog result we have you know does method method so we have to call this one and that's it okay and then we have to store a variable so where just blocks so we have create a you know property we have assign this you know whatever return type we have assigned over here but see the return type is a you know let me zoom in so return type is a domain entity okay so we have to convert to our view model okay so there's a two way okay so we have to you know there is a two way to convert you know whatever our domain entity to our view model entity so we can use that you know IMAP that is a best way actually to use here okay but that is take some time so I will do I will create a separate session for that to convert you know domain entity to our you know view model entity okay which is using imapper okay but as of now what I will do I will just convert you know this normal normal way like you know just select you know use the link you okay X create entity and just get a Lambda expression that view model and then just author equal to X author the name description [Music] and what else is pending is a pending I guess ID as well okay so let me fix it and then break this line to here and also break one more line and then finally what need to do convert to to list so that whatever you know whatever data it's looping through and convert to here and then create a list okay and then finally we store uh blog list okay and finally we have to return okay yes so that is done but yeah in the next session we'll convert you know we will create a imapper we Implement I mapper in the screen architecture okay in this application layer and we'll we'll use that one okay so but as of now this is sufficient for the get blocks so what we have to what we have to what we have to done so just need to recap so that we can understand again okay so in this get blocks query Implement what need to do first we have to create you know the view model okay whatever view model we have to return to UI and the presentation layer so we have to create a blog beer model and then we have to create a one query okay there's a two way also this uh create a query uh like using the record on using the class okay and we use the interface I request interface and return type is a response type is you know list of blocks and then we create a Handler and in this Handler uh we again we have to use the I request Handler interface and then use the request get Block query and then whatever response we want and we have Implement uh that interface method and here we have to put our logic our business logic okay so we'll inject also our you know abstraction class I block repository and inside the typical repository we'll call our method and just we have to convert and return back to there okay so that is fine for this session next session actually or let me just revealed will show that is there any issue or any error so that we can make sure uh there is no error okay see let me zoom in so there's no error it is succeed okay so yeah next session will cover will create a session of IMAP or how we can Implement IMAP and convert it to two you know that entity in our domain entity to our bu model entity okay to implement that I mapper so what need to do actually see I already create a structure of that you know cleaner question the application layer and in this application layer I have already you know create a comma and inside the comma in the mapping so whatever the mappings we have to do in the skill in architecture we have to do we have to keep inside this mappings folder okay so let me create an interface okay not a class it should be interface so let me name it to I map from interface okay so make it to public okay and it should be a generic because I'll create a IMAP bar which is just generic so that I can use I can use any entity okay and uh what need to do I need to create a one Declaration on this interface it is called mapping and inside the mapping we'll use that profile we'll pass the profile and this profile will just assign to profile whatever profile profile dot will create a map and inside the map build map actually mapping so just type of whatever object we'll get okay so this is a generic entity and then get type whatever get type over there okay so this is done for IMAP from interface okay let me implementation let me do the implementation okay so how we can do that just create a class okay the class call it to mapping profile okay so let me create that mapping profile class and just need to inherit of that profiles profile profile profile class okay and we need to create you know we have to create you know we have to create one method okay first we have one first we have to create a new Constructor okay and just remove the byte name space okay and just we have to we have to we have to do some logic okay so that whatever object will get from that entity so we will map maybe actually using the reflection we'll extract the property and value and then we'll map over here okay so that logic we have to return so let me create private void and just give it to name like for example apply mapping from assembly okay and pass it to the parameter call its assembly and we'll have to do some logic over here okay so let me copy paste because there's a huge line of code to you know to do these things okay so yeah see first we have to type cast type cast of that you know interface and then we have to trying to mapping whatever object we'll get you know in this method name and then we have to do something in the uh the definition and these things okay and then we one by one we get the list of that so assemblies types whatever types we get okay and then you know we create a profile argument type and then each types actually whatever the list we are getting so based on the East type actually we'll do one by one get the property and assign to convert over here okay so this is a straightforward you know implementation okay so it is a genetic thing so don't worry about that just you know use and copy paste and use your application that's it okay and also it is a very straightforward nothing it's more complex okay and what need to do now just call to that method so that whenever you know calling this mapping profile so this method will call and will actually uh you know take that assembly and just you know map to that object okay so call to apply assembly from that get assembly okay assembly to get assembly okay that's it Ctrl KD so that create make a you know formatting this class okay that's it and save it and just open okay and that is done for implementation of IMAP Chrome okay and now how we can call this you know map and things okay so we have already you know we have already have one class of configuration service okay in this configuration service actually we already create see the automaper you know uh we have register actually automaper and whatever assembly so already we have we have registered okay so in this case uh we don't think we need to do anything okay we already actually registered this automaper assembly okay so I think that resolve the dependency we didn't do anything over here okay but yeah once we'll run and if there is an issue we'll fix it fix it okay and okay so let me call how we can you know how we can call that imapper and convert to our you know domain to view model Okay so to that part okay first we have to inject that I may per class okay so how we can do that I mapper just insect no I mapper okay and just create a is create a field and just same things we have to create a initialize and then inside the Constructor inject inject the IMAP just initialize okay and then what need to do just comment out this line okay and see maple when you create a mapper and this in this mapper dot we'll call the map and inside the map of whatever uh whatever things you want to map okay so I want to map that list of view model a block view model okay Block B model 2 what is the destiny what is the source source is this okay so this is a domain see this is a domain list of you know domain entity list okay and this is a source and this is a destination Okay so that's it and just we can just return this one or just create a where blog list okay see the mapping is done but one thing we have to do this is the C this is a one line it is done so every entity we can just you know uh we can map to directly over here like this one line code okay so that is in a very nice feature give us to you know imapper to you know convert to our entity okay and one more thing we have to do go to blog view model okay and also in this blog beam model we have to add you know uh that I mapper you know we have to inherit that IMAP IMAP from that interface IMAP from interface and then pass it to whatever we have to do okay so we have to do like we have to convert to this view model to block model OKAY blog entity so where is we'll get we'll get from this entity one okay see so that is done okay so let me recall what we have what we have do for this you know for this mapping okay so first we have to create you know IMAP form in a generic entry interface okay inside this we have to create in a one mapping um mapping and declaration okay signature and then we have to create an implementation over here that so that whatever you know assembly we get that imapper we can extract and we can you know assign to our whatever entities we have to we have to we have to pass okay so we have done from here and then we have to do registration over this you know configuration service so that we can you know resolve the dependency whatever I may per things we are doing okay so this line has to actually register our dependency okay and finally in this view model we have to map to you know IMAP whatever our interface and we pass to which one to be trying to map okay so this blog entity we are trying to map to this one so that's why we have just add like that okay so that is done let me try to build so that we can make sure there's no any error okay see we'll succeed there is a no error next session uh we'll cover this get blocked by ID let's get started so first what need to do uh first I need to create a you know query class okay of the get Y block and also why I'm creating in a one by one every why I'm creating is showing that on a one by one implementation because every implementation like you know get blocks or get by ID get by block by ID or you know create update delete so every things have you know some everything is a similar but yeah there is a some you know minor difference so that I want to understand I want to you know help to understand like okay what is the differences and how we can achieve if such kind of scenario will need in our real project okay so actually it is also a real project example so that's why I'm creating from the scratch and end-to-end Flow okay so first we need to create a class okay let me create a class okay the call is you know or get blocks by ID query okay so let me get that get blog by ID query okay create that class okay and then make it internal to public okay and then such as the class and same things what we have done in our you know get list of blocks uh query class so I need to inject you know I request I request okay and here actually what we need to return okay so we have to specify the return type of here that response what is the response we have to return over here so basically we have to response you know blogs view okay which is already created in my previous session so and also what need to do like see this query we need to record one ID you know ID parameter okay so that ID parameter how we can you know pass that ID parameter so we have to create a one property over inside this query okay it is very simple just passing the integer so if you want to pass the integer so you can give that you know for example I'm just giving an example so if I want to pass a parameters integer so I can set as integer or if you want to send a parameter as a class so you can send a class or you can send a you know parameter is like a string so whatever types you can you want to send your query so you can send it to here okay and just name it to like as here for this in this in this scenario I'll pass it to blog ID okay so that I can get that block ID from UI from UI and get that you know filter that from our DB and get that response of that blocks okay okay so that is done and then what need to do I need to create in a Handler so quite is done now need to create an and Handler okay so let me create same as it is get blog by ID query Handler Handler okay so same we have to just change it to internal to public okay and again we have to inject you know I request Handler okay I already explained in a detail in previous session so please watch that one okay so let's see this I requestional award is doing actually the expecting actually two overload method okay one is you know request and another is a response so what is our request our request is that query what is that you know we have create a query so just call that query cat get block by ID query so this this is that one okay and then what is the response be up to written back so we want to return back our responses blog view model okay and then what need to do see once you specify your request and response okay in this I request Handler actually it is saying like we need to implement okay see this does not Implement interface because this is the interface so we have to implement that interface okay so Implement an interface just you can just Implement okay uh just extract that method okay so see this is uh already created already generated create like a Handler handle and whatever request this is our request and this is a cancellation token and this is our response type okay and now in this handle we have to call our repository okay so where is our repository our repository is in our domain layer Okay so if you go to domain layer C here is our repository okay this is abstraction repository so implementation would be in our you know that uh infrastructure layer so that will cover in next upcoming section so so yeah don't worry about that okay so yeah as of now we can we have to call this one okay in our domain layer in our application layer so where is that here Handler okay so how we can inject it is very simple just create a Constructor of that Handler class okay it is shortcut like ctor and just Tab and here you can just inject okay pass it to other repository as an inject and be up to resistor also you know this one in our you know in our API layer okay in our user interface so don't worry about that that I will show you how we can do that okay so yeah and also we have to create a assign a private field and assign to in in this Constructor okay so this is done okay and after that what need to do we have to call this we have to implement our method okay so this is our uh repository and in this deposit equal to our method okay where is our method get by ID get by ID async okay and in this async method see the expected is ID so where I will get that ID this ID will get in this request parameter okay in this request dot you will get that block ID which is we created okay see this is our query so this is our request in this request we have a requested which will be getting from user interface okay so go back to here okay and then see uh now it is complaining okay so what is this compiling is compelling just settle the response type okay so just make it to await and async okay also we have to return this block view model okay so but you can see just zoom in for little bit okay so let me again okay so see the response type let me zoom in again okay so see response type whatever our repository is returning is a you know domain entity okay so that needs to be convert in our you know that uh model okay so how we can do that but need to do simply you just in the ACT I mapper interface over here okay and change it to the you know because this is not private it is a simple like I mapper class so just create a variable over here and control dot just assign accurate you know that uh that create a private variable over here and then assign to your IMAP or variable okay so it is simple and then what you need to do just store a variable whatever response we are getting a store over here in our repository so we are getting this positive we are getting response of this you know entry domain entity okay and it is simple we have to imapper dot map okay and specify C destination what is the destination our destination is block view model okay and then what is the source sources this domain entity okay so we pass it over here and simply we have to return because this is our return type okay so this is this is complete okay let me build so that we can make sure everything is building fine okay see complaining it is not complaining any error it is not giving any error so yeah and just final rebuild so that we can make sure everything is fine okay so see this is done for this you know get by block and this next session will actually Implement in a command and inside the command we'll first create a will you implement that create blog relate Blog then update block okay so till now thank you have a nice day and please don't forget to subscribe okay so first what need to do first we have to create a one command okay so how we can do that just create a class okay make it name is uh create blog command okay and make it public okay and similar what we have done in last session uh simple we have to inject I request I request and then whatever our response okay so whatever our response about that blog view model okay so here we can just pass it to block view but as per that you know normally we have you know written in create command or obviously just you know integer like you know one Whatever generated ID okay so be up to you like whatever you want to return okay so you can just pass simply integer or you can just pass simply string whatever things okay but in this demonstration I'll just complete uh returning to this the that blog model and in this what is the camera view block model just ID name description author okay so it is simple and what is the request parameter we will get from Little UI okay that that uh from UI for that you know for instead of that you know that blog what need to required we require this name uh for that user will you know send user will send to the name what is the Blog name what is the description of that block what is the author name and what is that image URL okay and that actually that block model you can go to here see the block view model is already there so same things okay so I think here is a name description or author so we can keep it to same name description and author we can remove that image property okay so that's it the create you know command is created okay now we have to create you know one Handler okay so that whatever command they can proceed by Handler okay so let me create let me copy this name create block command and right click on that create a class and just paste it to over here and just adding to Handler okay create block command Handler okay make it to public okay now again what need to do similar thing we have to do I request Handler we have to inject I request Handler okay and here we have to pass same things again make this two overload method one is request and what is the response okay so what is our request our request is this create block command so just part password to create block command and just pass it to also response what we have you know what we have to return back to response so our response would be like similar model okay and similar similar again we have to implement that things okay so Implement interface okay so now it is creating Handler handle method and now we have to handle whatever our you know the business logic over here okay how we can do that simply we have to create a Constructor okay CTR and then finally we have to inject that our domain domain repository so here is our domain repository repository see I block I block repository so call it to here if you don't know about how we can what we are doing here so definitely recommend go to my previous session or you know from that project setup so definitely you can understand like why I create that Dom inside the domain I repository or something okay so that is done and then what need to do we have to assign a private property and then assign in this Constructor okay that is the inject you have to inject at an I block repository so I did that and then we have to call to our method okay so what is our method to create a block so this is that method create a sync okay and in this create a sync what is expecting this is expectancy domain entity block okay but here see what is the entity it is a different entity so it will not expected actually so what need to do we have to convert so this is that way like you know we can convert like imapper or we can directly you know just change it to the things like this like suppose for example where and just store that you know entity blog entity okay and then new uh what is that entity it is a Blog entity okay and this blog entity just pass it to our parameter okay like for example what we are getting okay we have we have as a name property so we have to assign from that requested name okay similar that description so in this description also request dot description and let me remove that okay so that we are able to see that okay then author an author also like that request Dot author okay we are not passing ID because ID will generate automatically so this on entities created with this blog domain entity block domain entity so just pass it to here okay and then uh this is a you know a sync method so definitely we have to use that a waiter sync okay and finally so in this method see in this method actually repositories is returning its domain entity okay so again in this domain entity what need to do we have to convert to our view model in this model okay so similar things we have to just store over here like uh created or result you can just post up the result as a variable as a result okay and then finally what need to do we can just map it to uh we have to use that mapping okay so how we can do that it is very simple I mapper I mapper to mapper okay which is already I Implement if you don't know uh so place my preview please watch my previous session okay and just create a private field and assign to in this year inject in the Constructor level okay and then call it to here I mapper Dot map okay and what is that you know destination destination would be our blog view model and what is the source source it is our result okay and finally just written as a return okay see just formatting okay so this is done okay so this is sufficient for this you know that create blog but yeah one more thing will Implement in later okay not here yeah so so that that validation part okay see whatever request we are getting from UI we are not validating we are directly actually might be could be you know could be that you know could be that command so this is our Command so might we could be users and this command is as a null or you know empty something like that okay so that we will we will you know create some you know some common we will Implement some common logic okay and that will actually will you we need to use for that you know fluent API uh package okay so that package will help to uh you know validate our entity whatever user is sending so we can prevent okay if it user name sending is empty or something or whatever validation we required so we can set via that freelance API so that will do in later okay first we'll just cover you know everything like create delete update then finally we'll show you how can validate with the fluent API so that will will do in the upcoming session okay so till now it is fine so let me build so that we can make sure everything is working fine okay so now see will is succeed and also it is running perfectly okay so that is done for that create blog implementation okay and later on on the next video uh will actually Implement that update part okay start it to update query okay so what need to do first we have to you know create one come uh one command similar what we have achieved in so far last session okay so simple what need to create it is a update blog command okay and then in this update command block just make it public and inject is you know simple like that similar I request Handler I request number and what is the response type because it is update so definitely once update we'll need to get just you know that ID okay based on this ID okay it is updated or not so just return as an integer like whatever updated property updated ID okay so we just we can return it over here and okay now what is the response type okay so means request type like whatever request we are getting from that user so that we have to pass over here okay so where we'll get that that should be up to yes per year uh requirement but yeah in here in this in this year actually we use one you know blog view model okay so where is I created that one I created I think somewhere in here okay yeah see the blog view model so I can this property we have to get from UI so that I can update this property in our database okay so create this property okay so in update command what we'll get from the user ID name description author same things we have to update in our DB okay so that is done command is created and now what we need to do we have to create a Handler update command Handler so how we can do that create a class just put some name like update block command Handler Handler okay and make it to public similar fashion and now again need to inject I request Handler I request I request Handler okay it is getting from this you know mediator and also the here we have to pass in a two overload method okay one is request one is response okay so what is our request same things like our request is you know update block command which is just we have created okay and then what is the response we have to back we have to return back our integer okay so let me return the integer only okay and then what need to do actually this request handle are actually complaining okay need to implement their their signature okay so what is the signature just Implement interface so this is our signature need to implement Handler handle okay and how we can do that we have to call our repository we are actually we have to send our data okay so go create a Constructor for that so that we can inject our I Repository this I blog repository okay so let me insect and create a variable and also assign create a private variable and assign to in in the Constructor level okay so that is done now we have to call our our you know Repository method which will you know update our blog entity okay so how we can do that just blog repository update async and in this update is sync actually see these are two things actually we need to pass let me zoom in okay okay let me let me zoom in okay see uh first parameter is an ID and second manager domain entity okay so that two things we have to pass okay so first ID VL will get will get from that request.request ID critical jet ID is our blog ID okay and then another one is C another one is is a domain entity okay so domain entity how we can pass it like simply new or we can just create this entity and separately then we can pass it over here like for example update update blog entity okay and just create a that you know domain blog entity okay and just pass it to whatever our parameters request ID to request study author to author and description to description and name is to name okay and ID or third name okay yeah that is fine that is submission and finally just copy this one and pass it to here okay and what is the return type of this method this is return type of this matter integer so make it two also this response response our you know written type is this method Handler method is a integer so just simply return with the await okay another sync that is done okay so let me build so that we can make sure is nothing we have missed over here okay so build is completed okay so that implementation also done so just recap what we have done okay because this is uh very important simply first what need to do you have to create a update command okay and then inject I request Handler I request interface okay which is you know getting from the mediator R okay and we have to uh pass that whatever response so in this scenario over update scenario we get the response in the integer okay and how we can decide okay what is the response we are getting okay so whatever implementation you have done in the domain okay now time domain actually just you know whatever your repository method like that time we have we can decided okay what kind of response we have to return okay that method so same same things okay we can just pass it over here and then we have to Once complete your command update block model command then we have to create a Handler okay and that's that Handler again we have to inject you know that I request Handler and I request handle also getting this in a expected this two method to overload method in a request and response and that request is our an update command block and responses in whatever written type okay based on this actually we create a you know uh implementation method in this I request Handler okay and here we will put our business logic okay and then call to our repository method so that whatever you know interact in database this will do in this in abstraction I repository okay and that get what the response over here and then get back to UI okay so that is done okay and the next section will Implement in this application layer the delete block let's get started uh okay so what need to do first we have to create uh that delete command okay so let me create a class okay we can put a name as it is uh delete delete blog command okay and similar what we have done in last session we have to do same things because delete also similar to not similar to update but yeah response type is the same so we will do we'll call that I request I request interface and then response type would be a integer okay and what is uh the request type request parameter would be in this delete command that we would be in a ID okay so based on this ID like suppose I want to delete a Blog five five which is I contain id5 okay so that we have to getting from UI so that command we have to see if I specify that parameter okay so that is done okay after that what need to do we have to create a Handler class okay just create a Handler like similar delete blog command Handler okay make it to public and similar fashion we have to do I request Handler and in this I request Handler we have to pass the query that request that is a delete block command okay and then response is integer okay we have to try to implement that method as well a request Handler okay so now we have to implement here like our business logic okay so how we can do that simply create the Constructor okay uh just inject your instruction layer Repository uh name is I block repository okay create a variable assign that variable at a private field and inject in the Constructor level that is done okay so for we update okay and now just call it to here the type log repository that delete method and the little method expected is ID okay so where is our ID we can get ID from that command equals dot ID okay and what is the response type of this method it's the integer so just uh store as an integer or yeah we don't require a storage integer because just it is also response type integer so definitely just you know put that await a sink because this is a sync method so also just pass it the return type okay that's it so delete command also implementation done okay so just recap what we have done simply we have to create a command okay delete command and the trade delete command we have to pass okay what is the response type so response type would be as our integer and what is the request parameter the request parameter is the ID okay so we have to pass over here and then we have to create a Handler so in this Handler we have to specify whatever command we just created okay so that mentioned that as a request and responsible via integer okay based on this request Handler we have to implement that handle method okay and in this handle method we have to inject we have to call actually our domain layer abstraction repository okay which will contain actually that delete delete data from this repo from The Entity or in the database okay and once it's completed it's written back to our ID okay that's simple let me build so that we can make sure everything is looks good okay so as of now it looks good okay so now see uh in the application layer you know we have complete the implementation of application layer okay so we have complete Command we have complete the query we have also complete mapping but yeah we have to need to do something for the validation but yeah that will do in the later okay and because that is a not a part over here but yeah that is a something difference which is required yeah definitely we do that in our upcoming session okay so far we are good and now in the next session we'll Implement actually infrastructure layer what need to do first for implementing our infrastructure layer so this is actually outer layer of this clean architecture okay so first we have to adding some dependency uh packages so that actually be using uh some database provider okay so here we will use like we can use sqlite we can use SQL SQL server and many things so based on that requirement actually we have to add some uh packages Okay so in in this set in this session we actually using a sqlite so we have to use some packages so right click on that go to nuget packages okay first package we required actually Microsoft Microsoft Entity framework okay so let me add that enter framework search for that okay so let me yes Microsoft framework okay let me yeah so entity if Microsoft Entity framework core so let me install that one okay done okay then next would be not sqlite okay actually we using in this in this demo uh SQL Lite database okay so that's why we are installing this up if we if you want to you know change the years data provider so you can just change it to like SQL Server so you can just install SQL Server instead of the sqlite okay so for the demo purpose I am using this one okay so let me install that one also okay this one also done okay one last things we required for this infrastructure layer here are tools Microsoft entity core tools okay so let me search that one also just install okay that also done okay packages installing correctly you can see you can go to you know that project fold project file also you can check out and you can you know check like what are the things we have installed okay so these three things we have installed okay so that is done then we have to implement data so in this data we have to create one context okay so right click on that create a context uh create a create a class okay let me name it blog blog DB context okay okay so let me implement okay make it to public okay and just inherit that DB context class okay DB context okay maybe context okay once you you will get see this is inside of the Entity framework okay so that we can Implement our data data provider okay so let me create a Constructor okay inside the Constructor actually we have to inject that you know data data context option DB context action so DB context options okay and here you have to mention whatever your DB context class okay so our class name is DB block DB context okay and make it to as a set as a variable okay and then finally call to your you know um Base Class okay so Base Class it to actually the base class because it is it is passing then actually it's holding everything so okay so yeah that is done okay so then again one more additional we have heading over here so let me remove that one okay and bring that code so that you can able to see and I think one missing okay yes that is done okay so this simple you you if you don't know about that how we can create and what is the DB context class and how we can create it okay so please watch my you know that old you know some of the session actually I I explain everything like because this is part of Entity framework okay so you have to then learn something about Entity framework okay so that is done and then finally what need to do we have to create a DB set okay and I think we have extra okay so finally inside the class what need to do we have to set we have to create you know DB DB set okay whatever DB set actually we want to use for the card operation like insert update delete so here we are taking a one example okay so in this blog we want to insert up the delete okay so DB set DB set we have to pass our entity so what is our entity our entity name is blog so which is coming from you know domain entity layer okay and then finally you can you can set get set property okay that is done for this DB context class okay so this is submission okay so what we have done we have created a DB context class we have inject and DB context and inside the DB contact just whatever you know DB context options on this class we have just passed in the base class and then finally we have set the DB context okay so this is part of actually Entity framework so don't worry about that I explain everything in my some of the video you can go and you can watch it and you can understand okay how is that working okay and then finally we will implement the repository okay so in previous session or you know first session of the domain entity see we have created an abstraction depository okay so now the subsection repository we have implemented in this infrastructure layer in this clean architecture Okay so what need to do we have to create you know this implementation class in here inside that repository uh infosexual repository folder Okay add class just add I block repository okay done and then public make it to public and then finally what need to do just inherit that I blog repository okay and Implement all the method okay so see Implement interface so once you did this option so you will see all the method all uh you know as a implemented with this new Implement exception okay we will remove and we will do one by one implementation okay so first what we need to do first we actually we have to inject that DB context uh this DB context class so that whatever operation we will do inside this implementation so that we can you know we can perform on on there okay so let me in the act sorry let me create a Constructor okay so that I can inject that DB context class DB block DB context and and then finally we have to create you know field and assign a private you know create a private property and assign to in this in this Constructor level injection okay so this is done and actually this DB context actually will do insert update delete everything will manage over here okay so this is part of Entity framework Okay so first what we will do we will implement uh create okay so how we can do that it's simple very simple blog DB context okay and blocks dot add is saying there is a two method actually add or a addressing so we'll use edit sync okay and his addressings will pass that entity whatever domain entity we are getting okay and then finally we'll do blocks underscore blog context dot save change so whatever the entity we have added in this entry in this Entity framework so we will just need to save changes okay and also there is option of save changes async method so we will use that async method and finally we'll return blocks okay whatever new blogs will added will return back to UI okay and it is just complaining just because we using talks so we have to use async okay and make sure that of it okay so see this is done this is very simple like I want to insert update delete in actual DB context you know allow to that that all the you know operations like you want to uh your entity will be add insert update delete everything also save change roll back you know commit transactions and many things many facility provide actually as a DB context uh implementation in this Entity framework okay so let's move it to the next okay then we have to delete uh we have to do delete performance so let me ins instead of besting up times uh replace that code okay this is very simple again just use this okay and we are also see uh they required actually some async method so let me put some async method async and there is a finally then not the right name so delete blogs okay so see and also this is executed method it is inside of the entity feedback.com so let me bring that name space okay this is done also delete also done then finally get all blocks okay so how we can get that all blocks it is very simple just one line of code you can get that all the blocks from the database so simply blogs let me change this to correct name blogs okay also that name is not correct okay let me blocks and then finally a sync okay see it is also done let your you know inject DB context and then you can get that that DB set and then finally to list a sync okay that is also done then get y ID so let me copy paste and also change it to blogs blogs and change it to a sync and then change it to that names okay this is also done and then finally we have to update okay so here we have to update that entity okay how we can do that it is very simple okay so that getaway ID also this is very simple like see your um uh blogs data set and then finally you are just trying to fast and default finding this based on the ID whatever ID you're passing okay so it will filter give us two here okay and finally just implementally update operation okay and in this update operation we don't record here okay and dbcon text also just release the name and also block okay so finally is complaining something [Music] okay now it's done so see it is very straightforward implementation just inject your DB context class and in this DB context class just you can use and I'll just add a saying you know then and then you can just delete okay so delete directly you can just delete here and just you can get that all the entities and then you can just filter the entities and also you can just update the entity okay so there is a way we can use and we can Implement that you know blog repository or repository class implementation okay so this is done and finally what need to do we have to just make sure everything is fine just let me build this solution and so that we can make sure yes whatever implementation be update we have done so that is working fine there is no issue okay yeah see will succeed there's a no error okay but one more thing we have to do actually uh we have to resolve the dependence actually we have create you know debut context class we have create you know implementation of the block repository so all of things we have to actually resolve the resolve uh dependency okay so this is that's why actually in this layer actually the infrastructural year we have created a configuration Services okay so in this configuration service we have to resolve the dependency neither once you will use this one to Inner API okay definitely you will get that error it will complaining some matters okay so how we can do that it is very simple okay so first what need to do uh see I I created actually DB context class but we don't know what is the connection string and stuff okay so that's where we will getting from that UI okay API layer a user interface layer okay and that we will use over here so how we can do that it's very simple so services okay dot add DB context okay and in this add DB context what is our context DB context object name class name it is a block DB context okay so DB context DB block DV context sorry blog DB context okay and then finally what need to do you can just create some Lambda expression options okay and then finally okay let me options not appson actions okay options okay and in this options we have to ask okay what service provider we actually trying to use so okay so inside that options we will use we use sqlite okay see this is sqlite Vehicles b u b actually use that entry framework so we can use the sqlite as well as we can use uh you know SQL server but you have to add that uh you know packages for SQL Server okay but as of now for this demo I will use in this only and also one more things we have to passing over here from a user interface see I configuration so if configuration we have to get those you know connection string value okay so let me get that value over here configuration get connection string okay and then we have to specify what is the name okay so that name could be something like that block DV context okay log DB concept actually this name you have to you have to mention in our you know user interface API uh application setting.json file okay don't worry about that I'll mention once I implement it application layer I'll I'll explain okay and then what need to do just you know complete these things then just uh check if it is null okay if it is your connection signal so what we will do now we will throw the some exception okay so let me throw that exception then th Ro through through new your invalid operation exception exception and then we can pass some message okay so what is the message connection string block DB context node found let me you know just giving enough for you know as a logging purpose okay why it's missing where sometime might be we are missing that connection names in this our UI so definitely it will complaining and giving okay you are missing this part okay so we can get easily okay and then what need to do I think it is complete let me close that one and then finally bracket okay I think few of things missing let me fix okay so one two three so there is a one starting bracket second is starting betting and third is starting okay so this one you have to close here um this one you have to close here okay and uh this one you have to close here actually okay this one it's close here and here okay we have to add one more thing successful let me remove this curly brackets we don't require that one okay so that is fine okay so that is fix that is done so let me see let me just recap like what we have done we have create you know we have create at DB context okay actually we call the services and then inside the services TV cortex and what is our DB context we have just passed over here and then create options and inside the options we have to call actually which service provider we are trying to use so we are trying to use you know use sqlite so and pass it that configuration string and then if it is null so definitely through this one okay this is simple and straightforward and finally we have to we have actually create that you know implementation as well okay that I blocks reposited to I I blog repository to I block repository okay so that also need to register over here okay so how we can do that services Dot add transient okay so this is a method to resolve their dependencies so there's a three-way address transient at Singleton add a scope so there's other different different way we can do that resolvable dependency so here we will use for this service blog repository to blog repository okay so that's set okay let me rebuild again so that we can make sure is there no any error okay okay see we'll succeed it's done okay it's very simple like we have to we have to create let me zoom in okay it's very simple first we have to create a DB context class and then we have to implement that block repository and then finally we have to resolve our dependency over here okay it's very simple and this is done for this session okay and then this all the layer has completed like this you know domain layer infrastructure layer and application layer finally next session will come we will use how we can you know actually uh use those layer okay in here in the user interface and how we can call that you know application layer and get the data okay then next session will implement API so basically what need to do first in this user interface baby Pi okay so first we have to create you know One controller so let's make create One controller name uh let's make it one controller name is it create controller okay it is should be API control because it's a API so don't worry about that I just Implement an API as of now in this demonstration but yeah later on we'll Implement also how we can use that web application like in MBC and that clean architecture also how we can use this API in our angular or how can we use that killing architecture in in Mobile you know dotnet my view applications okay so don't worry everything will do in upcoming session okay so let me create a empty API controller let me put some name over here like for example it is a block controller so let me name is a Blog Okay so firstly what I need to do first actually see uh this is a sequest pattern okay so in this sequence pattern so I already explained actually why mediator are and how we can you know call that you know uh you know why mediator we need to use to insecurus pattern okay so I'll already explain if you don't know so go to my you know first session and actually first I need to create a mediator ad so that our mediator editor job would be like you know in the controller uh they will send a request and on get that response for this application layer okay without any dependency okay so how we can do that let me create uh one more uh class okay uh and class or just you can say the controller okay the name is again API controller name should be an API controller API API controller base okay let me put as a base controller okay and let me change to abstract so that this can be inherit you know other all the controller and we can use it very easily and also Implement enough declaration should be here and implementation should be there okay so that's why we put an abstract method okay and what I need to do I need to just create in a you know one mediator okay so I sender I sender let me call it to mediator let me create a private variable so let me name is underscore okay and then finally what need to do I need to create a fun declaration protected an eye center okay and then initiate and create a variable of that mediator mediator okay and then pass it to Lambda function and then assign to that private variable okay and after that if it is null okay also we have to some past some condition if it is null so definitely it should be some you know a status like the context to be context Dot sequest so yeah uh request Services okay and call it a method okay get record service and then pass it to I sender okay so that okay let me change it to these two and set okay so let's see if it is null so just this is similar as a function like okay we set as a you know the condition like if it is mediator would be null so definitely you know create an instance of that you know that for the current you know that current required service like I service okay so just uh you know initiate a method on this API control base controller okay and what I need to do this should be call to any other controller all the controllers so that I can easily you know change to here to that controller name so that I can Implement that functionality or that method and call to our you know uh you know application layer okay so how we can do that it is very simple again without dependency injector dependency so first I need to create a one get method okay let me create a sync and sync task then I action result and the method name would be then point name would be get all okay get all async async okay and finally our implementation so how we can do that it is very simple let me create a variable okay blogs okay and now I want to call our service okay that mediated service so where I will get this will be get from this in our base controller so let me call that name whatever we created and then call the send function and this function function actually actually asked to the sender request okay so I will send a request whatever our request so what is our query class the request query class is that which we have Implement in our uh you know application layer see if you go to blocks in the query so I want to call this guy so if you go so this is uh that query class of request query class so get blog query so this I need to call in our API controller okay so let me call this directly and that's it okay and see whatever we are get uh this is whatever written type it is a Blog view model okay so blog view model is a returning type so simply what need to do return okay call the OK method and pass it to our whatever data is getting okay and this is just implementation perspective done but see this need to do something actually for the DB creation so if you if you also watch my previous session so in the infrastructure layer actually see I just created a DB context but our contacts are ready but DB is not generated okay so DB I need to create a DB okay so how we can do that okay also if you go to my configuration see I have to use I use actually SQL light so in this sqlite I have to pass that correction string and then our DB will be generated based on this okay so how we can achieve that so go to your applications settings.json file okay first what need to do I need to create a connection string okay so let me copy that name okay so that we can save our time obviously simply I just put a variable as a connection listing inside the consisting I put a name like blog DB context okay and I as a SQL light connection is thing actually we have to pass like that data source where is our data source this is our data so whatever you now name you want to change you can put over here okay I just put like this way okay you can change s for your convenience okay this is first setting is done now what I need to do I need to check like all the references also is there or not so let's see there's a two references very important like one is infrastructure layer and second one is a application layer okay the two reference is done so that part also could so now what I need to do I need to fire you know two commands so that I can generate our DB okay so how we can do that it is very simple but first I think I need to okay no I already actually just configured that you know dependency uh layer wise dependency I resolve that dependency over here okay so nothing I need to do as of now okay so let me just fire these two commands so that our DB can generate it okay or or before generating DBS let me show you to run our application how is this actually behaving okay so that you can understand okay why I need to fire those command why I need to generate those I know okay so let me set the startup of API project okay and let me run this project okay see uh this one I I create a one endpoint so this and this is a default one okay so let me try out and execute see it is saying blog context is not found just because till we have not migrated our DB or we have not generated our DB okay so this will be empty okay so how we can achieve that things so it is very simple uh go to right click and go to manage console actually you can go to directly over here as well package manage console okay you can open this package manage console tab directly over here but I think here it should option as well package manage console it's not there okay if it is not there so directly you can use other option here as well in the tools in here see package manage console okay so you can go like two way like from here and here also okay so what I need to do I need to see our where is our entity okay so our entity classes is here infrastructure layer so what I need to do this is important actually you have to uh carefully uh do that actually without your setting it the DB will not generate you because see our there is a many layer okay but in in a structure here we are we are actually I generate our DB context so I need to set the DB context class and default project is that and the main project should be our API layer okay this two and also the other one another things actually we can directly put that command like okay one other primary is this and then then default is should be like that there's another command but yeah this is the easy way so I'm just showing you okay so what I need to add migration and then tab so see once you add and tab add an iPhone migration so you it will show you the that command name okay and then what nine I need to do just first initiate first initiate initiate initial okay initial and just add hit it is asking me is does not design okay so one thing actually missing that this package okay the package which we are looking is as well actually starting okay so this package is actually missing the Microsoft extender tool because those command will work because we are firing on this uh application user interface right so in this user interface this command will fire required that one package the name is this Entity framework tool okay so let me add the tool um manage nuget package browse name is Microsoft entity for network.tool okay and then install apply accept done okay once it's done let me make sure like it is there okay see this one is there let me zoom in so that you can download and install easily okay and now again go to package console let me add migrate that first initial then hit enter see again it's saying blog DB context is not found okay so something is wrong happening in my application so that need to figuring out okay so that could be happen like might be we have had many many things so could we happen like we have missed something so that also you have to know like okay some some kind of in things if we are missing so how we can resolve that okay so it is saying that block contacts not fun like connection is staying block context not one that means connection string data it is not found so let me check our name is C the name is wrong okay in here whatever I pass it or or just whatever I just hear mention in this configuration that is mismatch okay so ideally you have to do this to change to here or these two change to there so I would like to suggest change to this to there okay just change to the Earth and let me fire one more time okay see the start succeed and undo the section that means your migration has been done so let me verify what actually it migrates you see once migration done so this folder will be generated let me zoom in for you okay this folder will be generated inside this folder actually see the two class means to uh file will be generated also one is that you know that you know snapshot on one is another one is that whatever our query or whatever an entity okay so see in this year it generated create table it's blocked will be generated with this parameter okay and down also they're up and down actually so see there's up and down so it is created automatically and also in this snapshot you'll be able to see that actually what is that integer which property it in these are which part with that whatever things actually these are there okay so this is done and finally one last command we have to do over here then update database okay so see once you put that update and then tab you will you will to see that many command okay so what I need to use here I need to use update database so that so this see this is just generated Okay add migration just generated your data okay but once without upgradation it will not uh create you know insert in your DB okay so let me add this hit this command so see the it's generating okay you can verify as well okay see so see this TV is generated SQL DB is generated okay and uh if you open this DB okay so let me open our tools I have a tools equal light tools so that we can check as well like uh whatever entity is actually generated okay so remove this guy remove database the old one okay and just add a database choose okay where is our location so our location is clean architecture not this one clean architecture short one actually yes this one clinical inside the API folder this is a TV okay and just okay double click blog see this three properties generated as of now let me check there is a data or not let me find one query the data or there should be some fire query as well and a query let me find that query section yeah this is that insert query or delete query uh okay uh will comes later over here but yeah first I think we have to check that query section where is that query section okay so this is that section actually this is two Loop sqlite Studio inside this open SQL editor here you can just select star from blocks and you can just find a query like is there any data or not yeah there is no data so what I can do I can okay what I can do I can just run our application okay and uh let me see uh try out get the data see there's no data because as of now we don't have any data so let me insert one data as well okay so how we can do that I think there's option also we can insert like I want to insert one okay and ID I think automatic should update so let me name is C sharp the name is something description authorized kkp okay and uh just add okay so let me again find that query select star form blocks let me fire yeah now is one data over here so let me again fire our API execute see the data is over there let me debug so that you can understand the flow how is actually uh working like how is actually the and actually follow is working like on that that mediator I was working and secure as pattern how is working okay so let me debug over here okay let me debug finally over here okay and let me debug okay let me execute see debugger is here go to here and go to that class go to implementation okay click here okay there is no we can can't put over here but yeah where I can handle this request you can put debugger over there so let me open the query and Handler okay so put over here okay and let me F10 see once you have done your request is here and whatever request over here nothing just get the data from the your you know in this year blog Repository okay if you want to go here as well I can go to here as well just for understanding purpose let me again F10 go to here F10 see the repository in this block repository is reaching to you know infrastructure layer in repository and here it will get the data directly for the DB okay and get the data see data is over here whatever data and that's returning to here also it is mapped see data is getting from the repository then mapping also to view model okay right now it's uh converting is a view model and then return back to our controller okay and finally you are able to see the data whatever data is there and just continue see data is here 200 request okay so this is actually flow of sequence pattern with mediator are uh mediator okay so let me Implement another get request so this is a get all blocks but I need to implement you know in this session that killer get blocked by ID it is same similar kind of functionality I need to do what I need to do just another get endpoint okay but in this time we want to get the data by the by the ID okay so what need to do I need to pass okay I need to pass as an ID so it is a route parameter ID I think if if you know don't know about that how we can route parameter and things so I have old old session in for the web API session so you can go and check out and understand okay how is that working that web API router a router section okay so this is done then public also async and then task and then result okay I action result I action result and then finally call to get by ID async okay and then finally pass to that ID so that whatever URI parameter will get will map to over here in this parameter okay we have to pass same whatever we have used over here okay so ID and then similar again we have to call we have to store uh data we have to store one we have to create a variable local variable like blog and then call to our mediator okay mediator call that query mediators and method and inside the send method we have to call our this you know query request uh class okay so what is the name of that get get query get blocked by ID okay and inside here actually inside here we have actually if you go to implementation see we need to pass you know one parameter okay so how we can pass it it is very simple like see is already there just whatever class just close that class A create instance and then you have to pass that you know blog ID as a whatever input from the UI okay this is done and finally what I need to check actually there is a need to check one thing I need to check if this blog is null suppose might be sometime this ID is not match in our DB so that time I need to return actually but uh return to not found because data is not found so we can return to this this and otherwise just written okay okay so this is also done I want to just remove actually that default controller also just I want to delete actually the default controller so that no confusion okay so yes so let me run again okay now see this is another endpoint also get created so let me try if I pass to if if I don't pass anything so it will say okay it is a validation okay also if I pass something is not match so suppose 6 is not match so it will shows the four zero four or if it is match I think there's a one ID one is there exists so see it is there so one is returning okay so both are working okay so on this session that is sufficient okay and in upcoming session we'll cover that you know insert update delete okay those are things we'll cover in next session this is a baby PA layer okay here I have to go in this block control so in this block control we have created C we just minimal code we have just to call in API and we have achieved everything okay so let me create on that end point like post endpoint okay so first we have to create one HTTP post endpoint okay and then we have to create public async task and then I action result okay and then finally I have to call the method name is a create and then finally uh create block command okay call to the grid block command and finally I want to call that mediator okay and then mediator actually talk with the application layer okay so what I need to send I need to send that command uh whatever we have sending as a command Okay so that I need to send over here okay and whatever it is returning type it is returning as a Blog VM so just store is a where created blog actually it is a result of whatever you know getting the result okay after creating into DB so once it's done so I need to call this endpoint actually get y get yid endpoint so that whatever ID is generated okay based on the ID I just called again this get endpoint and get the data to user so that the user can you know confirm okay it is successfully generated or not okay so what we need to do just set as a return okay return and then create it on as a method created at action method what actually required in this method this is a three overload method so see I can pass the action name and Route value and that value okay so just pass to uh action name so name of okay name of action name is what is our action name it is get by get by ID okay and now I need to pass as a route parameter so let me create an anonymous object okay and then whatever expected route parameter is ID and where I will get that ID I will get the ID whatever returning type of that you know mediator or response okay and then finally I need to pass that value object okay so let me pass that object that's it okay see it is very very you know less of code and it is a clean that's why it's a clean architecture see it is a clear code okay so only just mediator are you know depend meditated are actually calling our application layer and get the data okay we'll get the response actually there is a no dependency direct dependency that's why actually it is a kill in architecture it's a very nice code and nice you know flexibility give us okay so this is done let me debug okay and see uh like how's that uh working follows follow the working okay let me run and see it's running and once I post click the post try out okay let me name it to uh clean or keep texture okay the Blog name is a clean architecture name is uh clean clean our key texture is a good approach okay now let me just as author name is kkp okay and let me execute see once you execute you will get the data means you will debugger point will hit here okay so put debugger Point as well here let me continue see I'll I reach it to application layer okay see this is our application layer inside the application layer actually uh go to commands and in the commands actually you will get that command Handler and command Handler actually that request comes up okay and then debugger just you know whatever entity return to the domain entity okay and pass it to our depository go to implementation okay so once you hear it is actually part of that infrastructure layer so infrastructure layer we get the entity finally it is called to DB context class and DB context class actually just save it and then return back to again AKC generated 10 and return back to our controller or application and then application to uh controller and finally it's called to our main endpoint let's get by endpoint and see this is just generated last change it is 10 ID is 10 and then whatever our our things it is just created okay and let me check in our console okay console also see uh it is generating a insert command see this is generating insert command okay see like select star from that blocks okay you will get the data and this is our one last one is 10 okay I think we are missing something like we are not giving the right DB name okay so now finally I selected and then get it so data is 10 let me execute one more okay let me execute one more like instead of green architecture let me call to Oak dance actually it is a new framework so octane's is uh good UI framework or allow to that's it I think that is sufficient okay execute execute execute continue continue okay so it is generated 11 and let me check in DB should be 11 yes now see this is generating okay so that's it for that post endpoint okay and in upcoming session actually we'll learn and we'll Implement like uh next two things the more two things is left in the controller like that delete and and delete and post a put okay so far what we have done let me recap okay so we have created you know just just zoom in okay so we created in our domain layer we have Implement domain layer we have infrastructure layer we have also you know that application layer now we are actually working on this web.net core web application which is actually uh we'll try to integrate you know our clean architecture and and do that you know inside of the delete and you know all the card operation Okay so let me open that block controller okay so in this block controller okay so so far actually see we implement the get we implement the Gateway ID also we implement the post okay now we'll Implement that put okay so first what we need to do I need to add one HTTP put okay to be put and then I need to create a one method okay let me create public task and then you know it is a just uh I action result I action result and just create it for that you know update okay and just pass to to parameters okay not yes to parameters so what is what are those okay so those are so uh first would be like integer okay whatever ID we want to update so those ID you have to pass and then another one is like what is the body okay so in this body we have to pass what are the you know parameter we have to update okay what are the field we have to update so we have already as a command we have already created that command so update update blog okay block block command Okay so pass as it is just such as the variable okay so if you go to this one if you go to implementation of that Block C It's contained like this four Pro three property ID name description and author okay same thing you have to pass in the body okay and now what I need to do I need to check first you know first condition okay there is a condition first like okay whatever ID okay so those IDE I have to match with this you know uh actually this this is this ID will come into the route parameter okay so let me Define that as a route parameter first okay so let me this is a Define syntax okay in the route parameter so if you if you want to pass any ID so you just mention this ID same name you have to pass so that they can actually serialize and you can get this ID okay so now what need to do you have to check this ID actually if not equal to you know this command this update command ID means this body ID if it is not equal to then what I need to do I need to just return is it is a bad request okay which is we saw in our demo uh demonstrations in this starting of the cell lesson okay so this is done okay and now what need to next what need to do the next okay so after that once the validation complete okay I need to call you know that mediator which we have already you know created in this you know abstract class okay so if you don't know so I'm especially recommend please watch my you know the previous session or I guess just or or just you need to follow the all the all my clean architecture session okay so let me call that method okay that mediator method mediator and then send a sync and then pass it to that whatever object okay so this is our object I need to pass and this is actually uh just the async method okay so let me pass that await and then await with async okay and then finally it is a return type okay so what I need to return in this method in this parameter and this what you call it's just a endpoint like put end point so I need to pass or I just need to return I know no content because I I nothing I have to return to user right so that's why I just passed to no content so that it is saying two zero four to user okay see the 204 status let me zoom in for you to zero four stars so that it is it is tell us like okay yeah a command execute successfully and it is updated successful okay so that's it for here okay let me put debugger point so that I can check it okay uh like how is that working uh flow flow is working is working over here like how we call C this is a minimal code we have just called to our clean architecture okay so that's why it's called a clean architecture only just one line code you have to call to here there's a node dependency of the application layer it will handle you know with the mediator r pattern okay so let me run this application okay and let's see like house working like how's the code flow is working okay with using a debugger point okay it's run and let me check how many how many day you know blocks is there okay remove that debugger Point old debugger Point okay okay now I have many many data over here so let me update this 11 okay the block ID 11 okay so just try one 11 and just pass it to 11 if you see that is at that place like if you not match this in or route parameter to body parameter so it will complaining okay it is better request okay so let me let me try it okay just execute okay see it is getting over here see ID is ID is 11 and command ID would be is 11. okay it is 11 I guess okay so it is 11 then it will update okay I suppose it should be I have to change actually to 11 to 10 okay got no issue I'll let me check like uh it is updating properly or not then we'll check the validation okay definitely this will not going inside to but request because this uh you know uh this condition is true right so okay now let me debugger point in our application layer go to application layer okay in this application layer go to here go to commands go to updates okay and go to update block Handler okay in this year just debugger Point put development and just continue see whatever you know uh web API controller it's send request to our API layer okay and those same request we have got okay which is we sending to UI okay what they're doing just you know just you know trying to map okay like see this is our you know view model okay this is a command and but our you know main depository which is you know connectivity with this domain entity okay so that's why we have just to convert every year okay so let me over here and also let me go to implementation so that be able to see that okay how is actually updating you see this is our you know infrastructure layer if you go to solution layer see this is the infrastructure layer in this infrastructure layer we have Implement like this insert update delete are repository along with this you know injecting our you know DB context class okay which is actually responsibility to you know insert update delete uh data to over database okay so let me continue okay see it is reaching over here so it is just update let's go back go back now see it is getting over here in the controller continue and now see that it is a 200 okay it is a 204 actually okay and now let me validate the data again over here like how's the data see the 11 data has been changed with this string string string because we haven't passed nothing over here right just pass this thing that's why okay let me just to you know that validation check okay just in the body I just passed to 12 but in the you know loud parameter I just passed to 11 okay let me execute okay debugger point is reaching there okay and now let me debugger see see it will fails so that's why it's going to inside and that it will return to battery request see the bad request okay so that is done for this session okay so that is done for this session and next session we'll you know Implement that you know delete how we can delete those blocks so that will Implement in our web API let me open and go to the controller okay if this is a API layer okay and go to that block controller and in this block controller we have till now only just get num HTTP get HTTP post put okay now we have to implement the delete okay it is very simple nothing we have to do just call it as a simple code okay and just call one endpoint so just create a one endpoint like HTTP delete okay inside we have to pass you know one route parameter based on this ID actually block ID we have to delete okay and just create one method async task okay I action result and delete this call as a method name is a delete okay and then pass it to ID so that whatever the route parameter it will match okay and then what need to do is just call to your mediator okay mediator which is inside your base class okay so just call this mediator okay if you don't know how we can achieve how we can Implement that one so please especially recommend to you go to my previous session okay so let's call this mediator and mediator will have a method to call you know our application layer which is interact okay and then pass to our Command so what is the our Command it is just uh we already just create a delete command Okay in this application layer so delete just although delete or let me check what is that command name which is we created so go to application layer and inside the application layer you open that blogs and then commands and inside that command that deletes and this this is a delete block command so let me copy this delete block command over here okay and then just pass to ID whatever ID we have getting for the UI and just assign to over here and that's it okay and just this is a sync of it async uh a synchronized method so let me fix that uh it's like quick line okay so this is just fish fixing and that it is asking a return type so what is our return type just check it okay so it is just returning integer so let me store as a integer integer ID or we can just return nothing because this that ID based on the idb I'm not doing any logic over here okay so what we'll do just simply return to no content okay because this is the delete method so here we actually that API we have to pass the 204 okay which is C this is saying two zero four is no content okay so that means there's a no content we have written to ey okay but yeah it is successfully uh execution successfully okay this is done let me put debugger point and let me open and see how is that working and it is very simple line code of that's why it's clean architecture called as a clean access so nothing dependent in the UI layer okay so let me open this delete okay let me check first how many records do we in in in our application in our database so see there's a many suppose we have to delete to 11 okay just put to 11 over here ID 11 and just execute see once you execute you will get this you will get this debugger point in this block controller and go to your Handler application layer Handler and inside the application layer Handler just deliver point over here and just continue see your application layer get this request and uh yeah 11 is request and then it is calling to infrastructure layer so go to that infrastructure layer uh Repository inside the repository just looking for that delete delete operation so see and then continue see it is reaching this infrastructure layer and finally they will delete from the DB okay it is calling the DB context and Entity framework to responsible to delete over here and then finally return back to our UI application and UI and then finally running your application and I'll run back to overview and they get that success 200 204 okay and let me check this 11 is 11 exist or not okay so so last one is 11 so let me execute C the last is 10 but 11 is gone okay similar if I put wrong parameter like not 10 it is not existed right now is 11 is not axis so let me execute execute execute okay so it is saying two zero four but yeah we can we can Implement such kind of things over here now or or such kind of things over here but yeah uh we have to not do that in this controller you know controller level okay we have to that validation inside that application layer so that will do in my next next session okay so yeah in this clean architecture how we can achieve that you know uh validation okay so we'll do that because there is no cell not make sense like we can put logic here we can do that like we can get that whatever return type is a ID so we can do that and we can tell us over here for example as of now just uh where result okay and based on the result if if result if result equals zero okay if it is zero so then definitely it's not found okay but written not or are just written bad request okay they turn bad request okay so this is one the solution but this is not a right solution okay so that's why it's just for demonstration I'm just showing you uh but in real scenario we'll achieve these things okay let me check again that 11. okay 11 execute and just put the debugger over here let me run run run see it is zero because there is no data is available but yeah see for this approach we if we going so that is it is wrong because it is going to you know end to end in our transaction and check in the database so it is taking the performance issue right because unnecessary if does not have any data related to that ID so we have to not call any DB okay and we have to not do all the flow need to execute okay that's why it's not all right things over here will do see it's bad request that is fine for the as of now but yeah in this application layer and in this application layer actually that will handle you know that you know handle that uh that validation you know inside this all the commands Okay we'll do in the next upcoming session open your application layer okay and inside this application layer we have a behavioral folder okay so inside behavioral we have to create one more class at a general gender class that will handle our validation Behavior okay so let's call it to okay let's add that class inside here okay and then one more things we have to check in our application layer go to manage packages okay is there we have already added or not that fluent dependency packages okay so if that packages exists uninstalled okay so that is fine if it is not there so then you have to install Okay so that is just prerequisition for this validation fluent API validation okay so what I need to do I just you know Implement here like C I need to create this gender class like request and response and I need to add that mediator our class interface okay so that whatever request will get that will handle that mediator run okay we don't call this class to anywhere okay it will call automatically while our Command query will send to our you know uh that is sending to our application layer okay and here just what need to do after you know here so just try to implement okay so go to implement interface okay and make it to you know just create to implement over here okay so how we can do that it's very simple first what need to do I have to create a Constructor for that okay so that I can whatever our request you know generic requests so that I can handle why the uh that that uh fluent API validator okay so the shortcut is Constructor CTR and then what I need to do I just create I enumerable and pass it to I validator okay and this is inside of C inside of that fluent API okay and then API and then what I need to do I have to pass the T request okay and then finally I need to add one variable okay and then I have to set that private private property and this field and make make it to assign inside the Constructor so we have to inject that validator inside that Constructor level okay once it is done what I need to do I need to implement I need to put some Logic for the implementation so what would what would be that let me just trying to copy paste over here okay it's very straight or simple let me make it to async so that that complaint can has gone okay it's very simple first we have to check whatever these validators it have any or not it will check once it done then we'll create a context and this context actually we'll try to validation the result okay and whatever validation result will get after that we check it is failure or not if any failures error on this Now command will store over this variable and then finally we have to throw that result and send it to next it is very simple nothing is complex okay this is done for this validation Behavior class implementation okay and make it to public so that this can be accessible outside of the class okay by mediator okay once it's done then what need to do I need to create you know that validation whatever where we want okay so first I'll show you in this create command so create command whatever the create command will come okay if any empty like we have not passed any things okay so then how we can handle like okay how we how they request we would know like it is empty it is not empty like that okay so what need to do first you have to create one one class over here that is called as a validator class okay uh validator create block command okay so let me copy this class name so that we can create a similar kind of you know following that name in conventions okay so yeah create block command validator okay so that is fine let me create that class and now what need to do we have to just um call that class okay whatever we have to create it okay so what is our class name uh not class that class but yeah we have a call is ABS okay see this is inside we have to call actually okay so what I need to call over here I need to inherit one fluent API abstract class okay so what is that name AVS abstract validator okay see it is inside of that you know fluent API validation okay so let me call it here and then pass whatever your command okay so what is our Command we need to edit I need to validate our create block command okay and make it to public okay and then what I need to do I need to create a logic inside the Constructor sort so that once it will get call automatically it should be you know for first fired up that you know validation okay now what I need to do I need to write some validation logic over here okay so let me get this code okay it is very simple see I need to call rules four whatever our entity okay so that entity refer for this command one okay so once you referred so you will get all the property over here okay see whatever property you will get over here so I just pass it to you know this one for the name name is required see require rules for this and then we have to set that okay it is not empty then name is required and also we have said that maximum length or say to validation we have to put over here same things for description we just passed the not required and also not empty and not required okay and that is done for here okay and then what I need to do the last things we have to set in this configuration that that fluent API configuration okay so that whatever assembly we'll get so that automatically can file okay so how we can do that it's very simple let me call that is important actually Services dot add validator add add validator assemblies add validators from assemblies Okay add validators from assembly okay and then just pass it to assembly dot get assembly so that all the assembly will can get it over here and then what need to do the final things we have to do over here for validation okay ctg dot add Behavior okay and this add Behavior we have to pass or whatever I we have created that class right so that we have to uh we have to register over here so type of whatever I pipe line behaviors okay and in this pipeline behaviors whatever the question response we have to pass it over here and then what is the implementation of that we have to pass it over here so what is that we have implementation class as well that validation validation Behavior which is we created from starting okay validation Behavior okay same things we have to over here like request and response okay that's it see this only two things we have to do that okay let me recap again so you have to add you know add validate add validators from assembly okay and get all the assemblies execute assemblies okay and then inside here you have to add behavior and you have to resolve your dependencies okay okay I think some thing we have missed over here we have to just yes we have to bracket over here okay so these two things is done now let me run and check this Behavior Behavior as expected or not okay let me try to create without passing anything let me remove all the body and execute see it is working fine there is no issue okay so same things you can do for all the all the you know all the command like this I created created for create blog you can apply for delete you can update okay it is very simple so thank you have a nice day and don't forget to subscribe
Info
Channel: DotNet Real world example
Views: 12,618
Rating: undefined out of 5
Keywords: Clean architecture in asp.net core web api, clean architecture cqrs mediatr, clean architecture cqrs .net, clean architecture cqrs, clean architecture with cqrs and mediatr in asp.net core, asp.net core web api clean architecture example, clean architecture web api example, clean architecture with .net core, clean architecture with .net, clean architecture .net api, clean code web api, clean architecture asp.net mvc, clean architecture asp.net web api
Id: C8mh8cziDSU
Channel Id: undefined
Length: 192min 12sec (11532 seconds)
Published: Thu Oct 05 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.