Тёмный
No video :(

asp.net core - MediatR (CQRS) Tutorial & Tips 

Raw Coding
Подписаться 72 тыс.
Просмотров 66 тыс.
50% 1

In this video I explain how the MediatR package works and how I like to use it.
Patreon 🤝 / raw_coding
Courses 📚 learning.raw-c...
Shop 🛒 shop.raw-codin...
Discord 💬 / discord
Twitter 📣 / anton_t0shik
Twitch 🎥 / raw_coding
👉 Try Rider
www.jetbrains....
RD5K9-4TXXW-KMV3G-NYWSF-3ZSTP
Presentation By Jimmy Bogard (Creator of MediatR) - • Vertical Slice Archite...
Presentation by Jason Taylor (Clean Architecture with ASP.NET Core 3.0) - • Clean Architecture wit...
Videos by Nick Chapas - • Clean ASP.NET Core API...
My video about Middleware: • In/Out Middleware Expl...
Source: github.com/raw...
#csharp #aspnetcore #mediatr

Опубликовано:

 

21 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 206   
@Qrzychu92
@Qrzychu92 3 года назад
For anyone that likes the Response message wrapper, checkout F# and functional programming, the programs are written using those with much nicer usage pattern (imagine the whole program using LINQ)
@RawCoding
@RawCoding 3 года назад
and if you don't like being constrained by types and have easier access to meta programming try Clojure
@junianohjj4602
@junianohjj4602 3 года назад
This tutorial makes it easy to grasp concepts better from the bottom up. I am now improving a lot with MediatR. Great work!!
@RawCoding
@RawCoding 3 года назад
Thank you for watching!
@chamalliyanage
@chamalliyanage 3 года назад
Finally youtube has suggested me something valuable.
@RawCoding
@RawCoding 3 года назад
Glad we found you
@ahmeddan7734
@ahmeddan7734 4 года назад
clear and to the point. I like the wrapper implementation; it makes it easier and cleaner. Just wanted to highlight that it is useful to use .publish () method when you are working with microservices or distributed systems. Keep it up
@RawCoding
@RawCoding 4 года назад
Awesome thanks :)
@ilovepandaypoe6056
@ilovepandaypoe6056 3 года назад
amazing Anton as always!!!! You've explained something so hard easily....
@RawCoding
@RawCoding 3 года назад
Thank you )
@josephizang6187
@josephizang6187 3 года назад
very nice. Like the casual style you have to teaching this
@RawCoding
@RawCoding 3 года назад
Thank you)
@justaboutanything8506
@justaboutanything8506 2 года назад
Great tutorial, not only just MediatR you also taught other programming stuff.
@RawCoding
@RawCoding 2 года назад
Chee
@josemtz6430
@josemtz6430 2 года назад
great tutorial, I've been struggling with mediatr for some time now I have a clear idea about how it works, in my case I was a bit lost when you mentioned and described the pipe stuff I will look for more information about it to understand it better, thanks for this explanation, nice stuff, keep it up!!!
@RawCoding
@RawCoding 2 года назад
Cheers
@septinary
@septinary 4 года назад
Learned something new, thank you so much!!
@RawCoding
@RawCoding 4 года назад
glad you did!
@i.paradox
@i.paradox 3 года назад
On a good day you will find this type of video. Thanks a lot.
@RawCoding
@RawCoding 3 года назад
Thank you for watching!
@subinsadanandan5145
@subinsadanandan5145 3 года назад
Concepts nicely explained...
@RawCoding
@RawCoding 3 года назад
Cheers )
@pp-studio
@pp-studio 3 года назад
Thank you for amazing content. It's make me clear. Next, I will coding :)
@RawCoding
@RawCoding 3 года назад
Thank you for watching
@ievgenieris300
@ievgenieris300 Год назад
Wow, the UserId thing is exactly what I've been trying to solve now, thank you so much
@hasitha03
@hasitha03 3 года назад
Thank you. Learnt and applied. Easy to understand with ur examples
@RawCoding
@RawCoding 3 года назад
thank you for watching :)
@johnnycagebringbackdislike9806
@johnnycagebringbackdislike9806 3 года назад
Although I personally hate MediatR, I want to thank you for sharing example of Pipes. They seem to mimic .NET Core middlewares, so do not seem to bring nothing to the table though.
@RawCoding
@RawCoding 3 года назад
Yep it’s similar to middleware, though it’s at application level. When the time comes to move your app from server framework to other (Which I think will never come) you just move the mediatr calls. Just a matter of what framework you choose to lean on, but mediatr gives you portability
@niroshanmanoharan4295
@niroshanmanoharan4295 3 года назад
Great! A simple explanation. Thank you!
@RawCoding
@RawCoding 3 года назад
Thank you
@get_ready
@get_ready 3 года назад
Thanks for this video mate, really helpful. Especially the user id pipeline. I've been thinking how to deal with that user id claim for some time, and you showed me the way :) Much appreciated!
@RawCoding
@RawCoding 3 года назад
Glad to hear, thanks for watching
@jesseopjescherm
@jesseopjescherm 3 года назад
Hey man, just stumbled on your channel and really like your way of explaining. Real smooth and well explained. Great stuff and keep it up!
@RawCoding
@RawCoding 3 года назад
Thank you:)
@hadibazmi6340
@hadibazmi6340 3 года назад
really loved that keep up the good work my dude
@RawCoding
@RawCoding 3 года назад
Thank you for watching
@rgubri3711
@rgubri3711 3 года назад
Nice Video. You even taught me Advanced generics with the Wrapper classes :)
@RawCoding
@RawCoding 3 года назад
Thank you, glad to hear )
@sushil9984
@sushil9984 4 года назад
Excellent !!! You made it look so easy...
@RawCoding
@RawCoding 4 года назад
it's not hard once you've used it for a while
@TheMdecima
@TheMdecima 2 года назад
Hello, thanks for sharing, Great explanation
@RawCoding
@RawCoding 2 года назад
Cheers
@mtavakolinia
@mtavakolinia 3 года назад
Thanks a lot for this amazing tutorial man :)
@RawCoding
@RawCoding 3 года назад
Thank you for watching)
@AK-we3gu
@AK-we3gu 4 года назад
Amazing tutorial, much love for you bro :D
@RawCoding
@RawCoding 4 года назад
Thank you for watching
@balakrishnang5603
@balakrishnang5603 3 года назад
Great. Keep going
@RawCoding
@RawCoding 3 года назад
Cheers
@melusimgwenya5844
@melusimgwenya5844 4 года назад
Great tutorial i can't wait to toy around with this
@RawCoding
@RawCoding 4 года назад
Cheers, yeah this one is quite fun to use :)
@VipinBalakrishnan
@VipinBalakrishnan 3 года назад
Very nice tutorial, just a little question , Suppose your PipelineHehaviour you are doing validation. How do you manage Response type. How the DI work with this object when we do DI registration?
@RawCoding
@RawCoding 3 года назад
We don’t you create this response
@VipinBalakrishnan
@VipinBalakrishnan 3 года назад
@@RawCoding Sorry, i did not understand. I tried your tutorial with Response . I am getting issue with PipelineBehaviour in DI. This is my DI services.AddTransient(typeof(IPipelineWrapper), typeof(ValidationBehaviour)); /////////////////////////////////////////////// public class ValidationBehaviour :IPipelineWrapper { private readonly IValidationHandler validationhandler; private readonly ILogger logger; public ValidationBehaviour(ILogger logger) { this.logger = logger; } public ValidationBehaviour(ILogger logger, IValidationHandler validationhandler) { this.validationhandler = validationhandler; } public async Task Handle(TIn request, CancellationToken cancellationToken, RequestHandlerDelegate next) { } } /////////////////////////////////////////////////// public interface IPipelineWrapper : IPipelineBehavior { } ////////////////////////////// public class Response { public static Response Failed(IEnumerable message, T data = default) => new Response(data, message, HttpStatusCode.InternalServerError); public static Response OK(T data, IEnumerable message = default, HttpStatusCode code = HttpStatusCode.OK) => new Response(data, message, code); } ///////////////////////// public sealed class Response { public Response(T data, IEnumerable message, HttpStatusCode code) { Data = data; Message = message; Code = code; } public T Data { get; set; } public HttpStatusCode Code { get; set; } public IEnumerable Message { get; set; } } /////////////////
@RawCoding
@RawCoding 3 года назад
Please share that code on my discord server in the need-help channel
@VipinBalakrishnan
@VipinBalakrishnan 3 года назад
@Raw Coding The issue is some what similar to github.com/jbogard/MediatR/issues/466 , But here it is asking to change DI. Is this wont work in MS DI
@VipinBalakrishnan
@VipinBalakrishnan 3 года назад
@@RawCoding Sure
@anurag3487
@anurag3487 2 года назад
This video is gold, clear explanation. Appreciate your efforts Anton. What's your source to study?
@RawCoding
@RawCoding 2 года назад
Ty and I use the internet
@anurag3487
@anurag3487 2 года назад
@@RawCoding we all use the internet but you are on a different level. :)
@tinypanther27
@tinypanther27 2 года назад
What is the 'box' we trying to make portable(portify?) ? Moving the business logic to a framework other than ASP.NET Core? Also, I m unsure what advantage we get by having the controller action method know which query to send rather than having to know which business logic method to invoke. What was the motivation for hiding the business logic behind two additional layers of abstraction - query and handler?
@ahdbenkheder
@ahdbenkheder 3 года назад
Love your channel man. Any video about Generics class/methods?
@RawCoding
@RawCoding 3 года назад
Not really :D
@ssshyambabu
@ssshyambabu 3 года назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Q1Tv7vj3Txo.html
@mhDuke
@mhDuke 3 года назад
I will take a nap, then am going to go through the other resources in the description to try and find an answer for the following: if I want to run more than one command within single database transaction, how do I go about implementing this without passing the IDbContextTransaction object around? if you have insights about this, please enlighten me :)
@mhDuke
@mhDuke 3 года назад
I was about to implement sagas to cover a use case, but I thought if I can run away with multiple DbContexts on single physical database.
@RawCoding
@RawCoding 3 года назад
Do it in the pipe
@mw323231A
@mw323231A 3 года назад
Thanks!
@RawCoding
@RawCoding 3 года назад
Thank you!
@mohamedchaabouni4477
@mohamedchaabouni4477 3 года назад
Correct me if I'm wrong ! but the fire and forget I use it personally for firing the send notification or sending email to a user after some checks that the current user that executes the code don't wait until the system sends the email or notification to the user to finish the request.
@RawCoding
@RawCoding 3 года назад
You can use it like that, but what about retrying if it fails?
@psceok
@psceok 3 года назад
Hello, great explanation ! I have a question. Is it worth to implement Repository pattern with MediatR pattern ? A) For real life projects B) For learning purposes. Does implementing them together makes sense, and can be used in real life web applications ? BR and thanks in advance !
@RawCoding
@RawCoding 3 года назад
For learning MediatR no, your repository should be some kinda data storage abstraction, so it makes sense if you need to change the storage provider.
@obigbaebruski5066
@obigbaebruski5066 3 года назад
First time am seeing your tutorial video, and I must say I can't wait to take my system on a ride with this. Nice job bro 👍... Is there any other way we can achieve this without using those nuggets packages? Cuz it seams the whole process rely on those packages...
@RawCoding
@RawCoding 3 года назад
Make it yourself
@madd5
@madd5 3 года назад
@@RawCoding LOL
@terryaney73
@terryaney73 3 года назад
Would you see making N 'Service' projects the right way to go? If you have say, 2 databases and another 'web service' as the 'data sources'. Or would you put all in one Services project. I was thinking something like Data.Services, Authentication.Services, Amazon.Services (for example)...still learning this so could be completely wrong.
@RawCoding
@RawCoding 3 года назад
I can’t recommend it because it makes sense for different projects. Some need it some don’t, abstraction takes time and you have to know if it’s worth investing.
@arashghelman5332
@arashghelman5332 3 года назад
Should I return raw data from my services and wrap them in a response in my controllers or return already wrapped objects from the services? Which one would you recommend?
@RawCoding
@RawCoding 3 года назад
I don’t quite know your use case, but I’d wrap it at service level.
@user-ck5ko5gn7c
@user-ck5ko5gn7c 4 года назад
mediatr look like a useful decouple tool,thank you for this tutorial。 but i was confused by those interceptors,etc middleware,fliter,mediatr's interceptor,ioc container's interceptor,db orm's interceptor...
@RawCoding
@RawCoding 4 года назад
I recommend to watch my video on middleware, link in description
@MaxLaurieHutchinson
@MaxLaurieHutchinson 3 года назад
Thanks, You have helped refresh my memory for MediatR, what shortcut/command are you doing to make those files/classes, its soo quick?
@RawCoding
@RawCoding 3 года назад
If that’s in visual studio it’s the add new files extension
@MaxLaurieHutchinson
@MaxLaurieHutchinson 3 года назад
@@RawCoding thanks
@thomason993
@thomason993 3 года назад
Could you consider making a similar video explaining the Repository pattern in the future? Thank you very much for your videos!
@RawCoding
@RawCoding 3 года назад
I’ll consider
@AtulRastogiKumar
@AtulRastogiKumar 2 года назад
Really helpfull
@RawCoding
@RawCoding 2 года назад
Cheers
@GorgeousPuree
@GorgeousPuree 3 года назад
Thanks for your video, but I have a feeling like I didn't quite understand what's the difference between middleware and cqrs pipe. They both intercept request, do some extra functional and pass to the next handler. Looks like they are interchangeable ? In which cases I'd rather implement my own middleware/cqrs pipe?
@RawCoding
@RawCoding 3 года назад
Middleware is tied to asp.net core framework the pipe is tied to Mediatr so it’s a bit closer to business logic. Let’s say you want to transfer functionality from backend to Xamarin app, you can’t shift the middleware but you can shift the pipe.
@GorgeousPuree
@GorgeousPuree 3 года назад
@@RawCoding aha, I'm getting it a bit..
@shahabjoon201
@shahabjoon201 4 года назад
Hello, thanks for sharing this amazing experience, but one question: what is the name of the FONT you are using in your visual studio? thanks in advance
@RawCoding
@RawCoding 4 года назад
JetBrains Mono
@madd5
@madd5 3 года назад
хороший урок, молодец.
@RawCoding
@RawCoding 3 года назад
Пасиб
@tony-ma
@tony-ma 3 года назад
Can you please do a video on MassTransit project? It can be used in conjunction with MediatR. I got confused as I thought they are doing the same thing. If used in conjunction, what is the responsibility for each of the package?
@RawCoding
@RawCoding 3 года назад
Never used it so I’ll probably not cover it
@abdelrhmanahmed1378
@abdelrhmanahmed1378 2 года назад
5:50 how you get the pop up ,and why in 32:22 the unsupported error shows up ,despite i can call an endpoint without sending anything even if it needs something , but it will just initialize the object to null
@joseluissuarez4093
@joseluissuarez4093 3 года назад
Hi, first at all, this is a nice example. I have a question related to the example at 25:24: I think UserId parameter has been added to the request. So if you are using Swagger you will see a new parameter exposed to the clients, but this value is calculated in the pipeline. Is it possible to hide it or just mark it as calculated?
@joseluissuarez4093
@joseluissuarez4093 3 года назад
Well, after thinking a bit, the solution was declare abstract to BaseRequest ;)
@RawCoding
@RawCoding 3 года назад
Not sure what you mean
@joseluissuarez4093
@joseluissuarez4093 3 года назад
@@RawCoding Hahaha! No worries. I can try to explain it better... In BaseRequest class you have added a new property (UserId). It means that all the clients of this Query (Can't remember if it was on Query or command example) could set UserId during the request. I was wondering how to hide UserId parameter from the clients because it is filled in the Pipeline.
@RawCoding
@RawCoding 3 года назад
What do you mean hide UserId from the clients?
@joseluissuarez4093
@joseluissuarez4093 3 года назад
@@RawCoding Let´s say you want to use GetAllCarsQuery in another Controller. You could do something like this: mediator.Send(GetAllCarsQuery { UserId = 1 }). So, my question was how to make this attribute not accessible for classes that use this Query.
@codewithkashif
@codewithkashif 2 года назад
I have a quick question i.e. why people use MediatR with CQRS only?
@RawCoding
@RawCoding 2 года назад
Not only
@emadradwan9400
@emadradwan9400 3 года назад
Nice work. Do you think Mediatr is also suitable for simple logic checks that's not CRUD? Its a query after all, but does it deserve the boilerplate for the pattern. I'm not going to return a DTO here, it may be a simple yes/no question to the API that will guide the logic from the client side to decide how to proceed with the app. And if not, what is the best practice here?
@RawCoding
@RawCoding 3 года назад
Sorry I don’t understand your question.
@emadradwan9400
@emadradwan9400 3 года назад
@@RawCoding I practiced the Mediatr pattern in a project that has the typical clear architecture structure of project where there is a dotnet core API project with controllers and an Application project for the business logic where MediatR is used. On the client side I'm using React and Mobx. For the usual CRUD part of the system MediatR is very fine and in case of Queries I send one object that is usually a parameter(s) list and get back - using AutoMapper - a DTO or whatever I need back from the DB. My question is, while i'm on the client side I need a small piece of info from the API that will direct the flow of the program - e.g. display React component A or B - is it ok to use MediatR also for such query or just do that in the controller for example. I'm not sure if MediatR is the right choice to get that info from the DB as we're not returning business objects here it maybe just a yes / no flag! What do you think. I hope I'm clear this time. Or maybe in other words, shall you use CQRS for all communications with the DB or maybe there are other patterns to consider in my case? Thanks for your time.
@RawCoding
@RawCoding 3 года назад
Mediatr can be used for this yes. Although I still don’t understand why you specifically need Mediatr
@emadradwan9400
@emadradwan9400 3 года назад
I need it to standardise on cqrs for the whole app. Maybe an example will make it clearer if you allow me. I have a grid that shows a list of parties and there is a parties table. The party can either be a person or a company and there are tables for each connected to the main parties table that just contain the common properties of each party. When the user click on a partyid in the grid I want to navigate to a full record screen showing either a person or a company and I use mediatr for that. The point here is that I can pass the partyid to mediatr and determine the party type inside the handler but mediatr need to know what response object type it needs to return and at that moment I still don't know yet. I'm not sure what is the best solution here. Shall I make two calls to the api. One to determine the party type and decide based on that. And if the first check deserve to have a mediatr call by itself to know the part type or what!! Appreciate your help.
@RawCoding
@RawCoding 3 года назад
So you can put partyid and partytype in the url query, what does this have to do with mediatr?
@adamali89
@adamali89 4 года назад
Thanks sharing your experience i need to clear one thing about MediatR that how Pipeline can be configured to be run before or after the command and query ?
@RawCoding
@RawCoding 4 года назад
Hey I am pretty sure I explain that in the video. Pipe will run for all commands and queries, what I do in the video is just specify what to do if it is a command or query
@adamali89
@adamali89 4 года назад
@@RawCoding i think you did not get my point let me clear with an example i want to authenticate the user before processing command or query and also want to log after processing command or query how will i configure this in the DI container. i have been working on MediatR i added validation behaviour like below and it is working perfectly fine but how mediatR know this validation should be run before processing command or query e.g... services.AddMediatR(Assembly.GetExecutingAssembly()); services.AddTransient(typeof(IPipelineBehavior), typeof(ValidationBehavior));
@RawCoding
@RawCoding 4 года назад
Register the pipe before you register the command/query processing pipe
@adamali89
@adamali89 4 года назад
@@RawCoding yes even in above case i have registered after mediatR service but it is executing before command query anyways thanks :)
@szymonurbanik1673
@szymonurbanik1673 4 года назад
Is there any way to register behaviorPipe on sending the command? cause from my understanding behaviorPipe gets executed with each mediator.send() so with bigger projects i am going to end up with 20-30 pipes that get executed with every mediator.send(). Let's say i create only one pipe for authorization that gets all the validation objects and then checks the types chooses the right ones. But what about custom validatiors that need to call db. How will dependency injection work with all the authorization classes and dbcontext and pipes. Am i going to end up with a memory leak or something? Do you have maybe some blogs or videos that tackle that sort of problems?
@RawCoding
@RawCoding 4 года назад
> Is there any way to register behaviorPipe on sending the command? Just inlcude that functionality in the command it self > so with bigger projects i am going to end up with 20-30 pipes that get executed with every mediator.send(). dubt you will be able to reach 20-30 I will be suprised if you can give me 10 use cases for using the pipeline. > But what about custom validatiors that need to call db. How will dependency injection work with all the authorization classes and dbcontext and pipes. It should just work > Am i going to end up with a memory leak or something? As long as you lean on the DI, no
@RajaKajiev
@RajaKajiev 3 года назад
IMHO this talk is more on asp.net core rather than MediatR. I was looking for explanation on problems which MediatR addresses, and you numbered some in the beginning of the video, but then you just forgot about the topic. Still worth watching thanks to a couple coding tips'n'tricks though....
@RawCoding
@RawCoding 3 года назад
Mhmm, I’d say I’m just talking about how to use it rather than when and for what problem
@tinypanther27
@tinypanther27 2 года назад
Why would you use such wrapper around your responses? If there is an error, indicate that with a 400 or 500 HTTP code. Why the need for bool error? Im not sure I understood the reasoning for the message property about translations??Isnt the data itself the message?
@RawCoding
@RawCoding 2 года назад
business logic -> other things -> framework -> http -> client the reality is your business logic sits quite far away from http, this wrapper is just a way to bring "structured response" closer to business logic so we can capture it and then the client can have common logic for processing the responses.
@tinypanther27
@tinypanther27 2 года назад
@@RawCoding but rather than modifying how an intermediate result is presented to the business logic, in this particular case we are modifying how it is sent to the external client living outside our application. we are sending back a 200 response indicating success in the header, but a boolean in the body suggesting failure. are there cases common use cases where the client would benefit from this kind of response? thanks for your response though
@bongguiao
@bongguiao 3 года назад
This is great! Just want to ask what was wrong with my implementation on the Respons. I copied the response.cs. How comes I am not able to access the Ok and Failed method? : IRequest , then in the command handler says Response does not contain Ok definition. Did I miss anything to implement?
@RawCoding
@RawCoding 3 года назад
Mhm not sure maybe your missing a using statement
@amJustSteve
@amJustSteve 4 года назад
I'm curious if you are aware of work done with Code Gen techniques to stub out a set of queries and handlers based on a given api?
@RawCoding
@RawCoding 4 года назад
Create custom templates, or swagger
@amJustSteve
@amJustSteve 3 года назад
@@RawCoding Custom templates. It's been a few months but I think I'd seen a presentation by someone outlining an end-to-end code gen strategy where even the unit tests were part of the code generation stream.
@RawCoding
@RawCoding 3 года назад
Umm yea not aware of that
@Neha-pn4hx
@Neha-pn4hx 3 года назад
Is there a way to handle a mediator object from becoming a God object?
@RawCoding
@RawCoding 3 года назад
What do you mean?
@Neha-pn4hx
@Neha-pn4hx 3 года назад
@@RawCoding What I read about mediator pattern is that in a complex application, the dependency on the mediator object increases, and it becomes God object (when object knows too much or does too much). How to avoid that scenario?
@RawCoding
@RawCoding 3 года назад
Dependency inject business logic and use handlers as proxies.
@Neha-pn4hx
@Neha-pn4hx 3 года назад
@@RawCoding Can you explain a bit further? by giving any example?
@RawCoding
@RawCoding 3 года назад
The same way you don’t want your logic in the controller and put it in the mediatr, now you don’t want it in mediatr just put it somewhere and inject the logic in to handlers
@GorgeousPuree
@GorgeousPuree 3 года назад
Do I have to pass cancellation token from controller into send method or MediatR takes care about it by itself?
@RawCoding
@RawCoding 3 года назад
Mediatr takes care of it
@GorgeousPuree
@GorgeousPuree 3 года назад
@@RawCoding thanks again
@clearlyunwell
@clearlyunwell 3 года назад
👍🏽
@RawCoding
@RawCoding 3 года назад
)
@patrykito
@patrykito 3 года назад
Hello, at the beginning I want to thank you for making such great tutorials. I really appreciate that you're explaining everything from the grounds up. I have got a question when it comes to implementing CQRS: Let's say I have an MVC app. I have a BookController with Create action method. Also I have a BookViewModel cause i need to validate some of the fields. So i am passing BookViewModel to the Create method so we have Create(BookViewModel model). Then I add CreateCommand with Handler. Now I need to map between BookViewModel and CreateCommand and send this command via Mediator. Here my first question comes: Does CreateCommand replaces DTO like when I would simply use services for instance _bookService.CreateBook(bookDTO book)? If I'm right I don't need DTOs when using Commands and Queries anymore? Following along, inside CreateHandler I need to add the book, so I have to map between CreateCommand and Book domain model this time. So the second question is: Am I doing it right?
@RawCoding
@RawCoding 3 года назад
why not use CreateCommand instead of BookViewModel ? it's just a c# object that you can validate as well. > Does CreateCommand replaces DTO like when I would simply use services for instance _bookService.CreateBook(bookDTO book)? I don't understad DTO's. if you need an class to represent some data make it. > If I'm right I don't need DTOs when using Commands and Queries anymore? Again I don't know or use DTO's, if you need a class to represent some data just make it. > Following along, inside CreateHandler I need to add the book, so I have to map between CreateCommand and Book domain model this time. So the second question is: Am I doing it right? right in what sense? if it works it works. You will know you have a problem when your solution will become hard to maintain untill then it's hard to say if you are doing something right without seeing the rest of the system. I generally think this is enough (try to have as little intermidiate objects as possible) public void Do(CreateCommand command){ ... _ctx.Books.Add(new Book { Title = command.Title ... }) ... }
@patrykito
@patrykito 3 года назад
Thank you for the response. From what you said I understand that I should just keep it simple. >right in what sense? if it works it works. You will know you have a problem when your solution will become hard to maintain untill then it's hard to say if you are doing something right without seeing the rest of the system. In architectural sense. I just wanted to know whether it's a good design flow assuming that we need a separation of concerns (viewmodel strictly for ui purpose, dto to pass only required data, and model for a database). I know it may seem too sophisticated and I could simply use one class for data representation but don't you think that implementing CQRS is also just making our app more complicated? I am sorry for stupid questions, I think's that's because I am beginner yet and just want to make a good software and get simple answers how to do that. Greetings from Poland:)
@RawCoding
@RawCoding 3 года назад
Not stupid question at all, I’d recommend to 1st keep it simple and only after try to predict realistically where do you need the separation to add the extra classes
@fp1030
@fp1030 4 года назад
thank you
@RawCoding
@RawCoding 4 года назад
Thank you for watching:D
@prabhakaranjagadeesan7749
@prabhakaranjagadeesan7749 4 года назад
Nice tutorial..pls share link for multiple list in command & handler.how to do it in mediator pattern.
@RawCoding
@RawCoding 4 года назад
Sorry I didn’t understand the question
@prabhakaranjagadeesan7749
@prabhakaranjagadeesan7749 4 года назад
@@RawCoding how to insert multiple list by using Mediator pattern & CQRS.
@brightlightdun
@brightlightdun 4 года назад
nice
@RawCoding
@RawCoding 4 года назад
thank you for watching
@zimcoder
@zimcoder 3 года назад
Do you have a real-world example tutorial of this?
@RawCoding
@RawCoding 3 года назад
No
@bekapochitev8144
@bekapochitev8144 3 года назад
ThanX Amazing Channel, and I have Question how to output count of objects in tables using MediatR??))
@RawCoding
@RawCoding 3 года назад
MediatR can’t do that
@bekapochitev8144
@bekapochitev8144 3 года назад
@@RawCoding Can I write anywhere?
@bekapochitev8144
@bekapochitev8144 3 года назад
@@RawCoding But MediatR can ouput List of Cars, So I just wanna Output count of Cars
@RawCoding
@RawCoding 3 года назад
If you want to get a list of cars from the database you’ll need to use some kind a provider native or dapper or ef core. In ef core for example you can .Count() on a table
@bekapochitev8144
@bekapochitev8144 3 года назад
@@RawCoding OK. ThanX for Answers!!!)))
@zbend
@zbend 2 года назад
What is MediatR doing for me over just my own injected service? Just c#
@hoangvunguyen2592
@hoangvunguyen2592 3 года назад
Can MediatR update Database ? I can't do that. Help me. Sorry, my English
@RawCoding
@RawCoding 3 года назад
Mediatr is not meant for that. It’s just to call a handler - your handler then needs to save to database
@Hari-gt6lv
@Hari-gt6lv 4 года назад
Super..
@RawCoding
@RawCoding 4 года назад
Cheers
@PaulSebastianM
@PaulSebastianM 3 года назад
Quick tip: normalize your audio tracks. Your volume is very low.
@RawCoding
@RawCoding 3 года назад
Yup thanks
@RameshKumar-so8lp
@RameshKumar-so8lp 3 года назад
ASP.NET Core MediatR error: Register your handlers with the container could you pls debug me this error
@RawCoding
@RawCoding 3 года назад
You haven’t specified where to load handlers from
@Ramesh_Kumar_
@Ramesh_Kumar_ 3 года назад
how can integrate the database in this architecture
@RawCoding
@RawCoding 3 года назад
Inject it in to your handler
@Ramesh_Kumar_
@Ramesh_Kumar_ 3 года назад
@@RawCoding there's a any demo there?
@RawCoding
@RawCoding 3 года назад
It’s standard dependency injection in dotnet core, if you don’t know anything about dotnet core watch my blog series
@Ramesh_Kumar_
@Ramesh_Kumar_ 3 года назад
@@RawCoding sure thank you I will follow your blogs
@rishikeshsharma5691
@rishikeshsharma5691 4 года назад
Hello, Thanks for sharing this excellent video. I have a question on how to use MediatR command within the angular component. looking for any sample or link.
@RawCoding
@RawCoding 4 года назад
I'm not sure what you mean. Just have your controller send a command to the API which MediatR can process
@chiragrajpal3760
@chiragrajpal3760 4 года назад
The scope of CQRS and Mediatr(library) is limited to server-side code. In Angular, half of the job(event-based communication) is already done when you use Observables, CQRS is completely dependent on how you shape your models.
@hatembaldam5374
@hatembaldam5374 3 года назад
Can i have more than one handler for the request
@hatembaldam5374
@hatembaldam5374 3 года назад
if no can you please make other one for the publish event to the event bus and subscribers for that event :)
@RawCoding
@RawCoding 3 года назад
Don’t think you can, I would make a single handler that calls the other 2
@otobest1671
@otobest1671 3 года назад
Hi, what is the font name you use ?
@RawCoding
@RawCoding 3 года назад
JetBrains mono
@otobest1671
@otobest1671 3 года назад
@@RawCoding Thanks
@saurabhchauhan232
@saurabhchauhan232 4 года назад
Very Nice video Sir, what is your name :)
@RawCoding
@RawCoding 4 года назад
Thanks, and it’s Anton
@saurabhchauhan232
@saurabhchauhan232 4 года назад
Really liked the last generic part.
@saurabhchauhan232
@saurabhchauhan232 4 года назад
@@RawCoding can you make video in docker with .net core api or with anything? also if you can have a video design patterns that you use often would be really helpful sir 🙂
@RawCoding
@RawCoding 4 года назад
Mmmm maybe some time in the future
@RameshKumar-so8lp
@RameshKumar-so8lp 3 года назад
Is any other architect there if yes pls specify me that
@RawCoding
@RawCoding 3 года назад
What?
@RameshKumar-so8lp
@RameshKumar-so8lp 3 года назад
@@RawCoding like mediatr design pattern architect like that
@RawCoding
@RawCoding 3 года назад
Singleton
@sdudnic
@sdudnic 3 года назад
"public class GetAllCars".... are you serious? I thought the classes are to describe entities, not behaviors.... "public class GetAllProductsFromNewYorkCity"
@RawCoding
@RawCoding 3 года назад
Some classes are to describe dumb data (entities). Some classes exist purely to hold functions (behaviour). It's generally bad idea to have a hybrid of the 2 - smart data, you don't want this because it harms your reasoning around the code base. Look up Data Context Interaction
@hyy1856
@hyy1856 2 года назад
0...