CQRS Doesn't Have To Be Complicated | Clean Architecture, .NET 6

preview_player
Показать описание

CQRS, which stands for Command Query Responsibility Segregation, is a popular design pattern. In this video, I will show you how to implement CQRS using the MediatR library. We are going to create custom Command and Query abstractions, to make our CQRS implementation more explicit.

Join my weekly .NET newsletter:

Subscribe for more:

Chapters
0:00 What is CQRS?
3:00 CQRS With MediatR
5:27 Explicit Command Abstraction
9:47 Configuring MediatR
11:20 CQRS Command Side in Action
14:59 Explicit Query Abstraction
21:10 CQRS Query Side in Action
23:27 Awesome Outro
Рекомендации по теме
Комментарии
Автор

Milan, quick tip. Just write a semicolon after the namespace and it will convert them to file scoped. Also ctrl+R & ctrl+G will get rid of all unused using statements.

danilodjokic
Автор

A separate video on how to actually use cancellation tokens would be nice.

majormartintibor
Автор

This is pretty darn cool. Setup my own project and followed your instructions. I did have to dig through some of the other videos in the series, but I got everything working. I enjoyed your explanation. Your explanation was clear and easy to follow. Thanks for sharing.

SamFugarino
Автор

Great explanation! I like your way to show this kind of content! Clean and direct to the point. Keep going!

rafapioli
Автор

I totally love these videos, hopefully one day you’ll talk about

joshem
Автор

Thank you Milan, I really enjoy your videos, you have clear explanations, straight to the point, no useless text that would make me move the video player's progressbar :)) keep going man.

calinmarian
Автор

Pretty good! The explanation is very clear. Gave you a like!

lexdxw
Автор

Great explanation and it's beneficial for understanding command and query concepts.

RahulLohar-lzwu
Автор

Great content!!
Would love to see how to create abstraction for a query when the response consists of properties coming from different aggregates.

javedahmad
Автор

Great Video! I cant get enough of your content. Can you explain a bit more about your Abstraction of Queries? As someone that primarily works with the data and DBA teams, I've seen a lot of different opinions on how queries should be handled to best balance performance, maintainability, and security.

silvertek
Автор

From start it is not clear why you create interface for query and command.
It is great that you learn and describe your material as well, it is good fast method.
I would remove ApiController, additional inheritance, additional object in memory without any gains.
Your own unit of work is anitpattern. EF already implement UoW in dbcontext object. Separate repository is also additional noise. Mediatr handler is independent implementation for single action. You make it depends on the common repository, which has many reasons to change. Also in my experience often repositories does not allow to reuse some logic. In different place the same repository action may require different transaction scopes, which repository does not address any way.

IldarIsm
Автор

My first video trying to introduce myself in the CQRS architecture since I need to work with it and got some concepts. Very well-explained, thank you!

jokersilva
Автор

Hey Milan, thanks for this great demonstration of CQRS. Could I maybe suggest a video idea where you show the full variation of the pattern? Including separate APIs, Read/Write models and Read/Write databases? All in combination with Mediator of course within the Clean Architecture & Domain Driven Design. I would be very interested in this. Thanks again for your valuabe content!

Sentrify
Автор

Hi! Thanks for your work. I stumbled upon your channel and I'm enjoying. A suggestion: at the beginning you mentioned (3:06) you've already implemented the CQRS (kinda) but it is difficult to find where. I'd love to see since the beginning and it's not easy to find some order in youtube. I've taken a look in the playlist but it's not clear. I'll watch all your videos but it would be great if you have some list (maybe in video description) ordered, it'll be easier for new subscribers.
Thanks a lot!!!

jmiltons
Автор

I understand all of this, except - whats the point of CQRS from the software point of view, if you have only one storage anyway. It worked without ICommand/IQuery interfaces & handlers just as well. I recently spent some hours debugging our current project, where for some reason data was not saved to dabatase, only to found that I inherited some service from the wrong interface (naming in our project could be better...).

able
Автор

I prefer to write my own solution for cqrs instead of making abstraction for mediatr it's not so hard. I prefer stick query handlers close to dbcontext instead of inject repository there. I like your videos, Keep going! :)

Dragonite
Автор

All this Clean, Super Clean architectural software design approach and this kind of video doesn’t say ‘You don’t need this huge complexity for your small to medium projects, or if you are a beginner’. If you just start your journey to software development road, skip this kind of ‘tutorials’ you will be overwhelmed and your brain will hurt. Just read the official documentation, make small applications, take your time. All this design principles and patterns are just tools that you will need on some, not all, projects. For small and medium projects this kind off approach will over complicate things. Trust me, you can build useful apps that don’t use any of this, keep them simple, stupid 🤪. I don’t say that this are not good at all, in big projects with big teams are a must, otherwise chaos will happen 😇. With time you will learn and figure out what and when you need to use it in order to accomplish your goal. Start small, learn the basics and build up your experience, otherwise you will lose precious time.

gligom
Автор

I like my Controllers to be dumb and short, so the requests they receive are the command parameter (or command itself) and the return is an AutoMapper mapped Dto.
Every API endpoint boils down to a one-liner like
return
Which can, arguably, also be simplified with a generic type...
Then I use Swagger/OpenAPI to generate the TypeScript models for the frontend to strongly-type glue the two layers together.

One drawback of this approach is modifications towards the frontend; builds will fail if the commands/queries signature changes are not adapted on the UI layer, which is also a benefit as you deny yourself space for error, mistakes are immediately apparent, there's no space for deprecations and the client will only receive a working build with no compile errors.

mptechie
Автор

What is inside the "Result" class? Would you show us?

winstochurgle
Автор

Would be really interesting to see how to separate the storages to the read and write storage and how to sync them so the command will write to the `write` storage and reads will read from optimized `read` storage.

yaroslavsmoliak
visit shbcf.ru