Intro to MediatR - Implementing CQRS and Mediator Patterns

213,813
64
Published 2021-04-05
MediatR is a tool that makes implementing the mediator pattern much easier. It also allows us to conform more easily to the CQRS pattern. Now, if I have already lost you, never fear. I am going to briefly touch on what each of those patterns is, why they are important, and when we would use them. Then we will see an example of how to use MediatR in our projects in C#.

0:00 - Intro
1:01 - What is CQRS
3:49 - What is Mediator
9:00 - Mediator Pattern
12:00 - Create BlazorUI app
13:24 - Create DemoLibrary Class Library
15:25 - When should I implement MediatR?
19:22 - Setting up DataAccess class
25:10 - Setting up BlazorUI app
28:18 - Adding MediatR Package
28:48 - Build out MediatR Setup
29:08 - Setting up Queries
30:08 - Difference between Class and Record
30:51 - Setting up GetAll Query
33:33 - Setting up GetAll Handler
38:30 - Configure StartUp (BlazorUI)
43:21 - Inject and use MediatR in a Razor Page
49:30 - Create DemoApi Web API
50:44 - Configure StartUp
51:52 - Create Controller
52:58 - Inject MediatR
53:26 - Implement HttpGet all
54:16 - Run DemoApi
56:27 - Setting up GetById Query
58:05 - Setting up GetById Handler
1:03:11 - Implement HttpGet by Id
1:04:28 - Run DemoApi
1:05:25 - Setting up Insert Command
1:08:55 - Setting up Insert Handler
1:10:34 - Implement HttpPost
1:12:38 - Run DemoApi
1:13:59 - Recap

Source Code: leadmagnets.app/?Resource=IntroToMediatR

Mailing List: signup.iamtimcorey.com/
Purchase Courses: iamtimcorey.com/

All Comments (21)
  • @georgesaeid7231
    This is the most elegant explanation of MediatR ever. Thank you.
  • @bardus_hobus
    Tim, I want to say thank you for all your videos. I have finally landed my first job as a software developer, and I owe it in part to your amazing training. I am now going back through your videos to review some stuff they use (such as MediatR) for my continued education. Thank you so much for helping me reach my dream job!
  • @Keiktu
    Mr. Corey. This video is pure gold!! Thank you very much for this video, I have been looking into learning CQRS and MediatR for a while.
  • @masygoli2831
    It was one of the useable tech videos I've ever seen in YouTube with simple yet powerful teaching ability. Thanks a lot!
  • Hey Tim, Like 7 months ago I finished an expensive bootcamp that.... taught me very little. I then signed up for your master class and completed it fully, A week after completing the masterclass got 2 very nice competing engineering offers. And here I am, today marks 1 month at my first engineering job AND my job happens to use Mediatr which you have now helped me understand perfectly. You da best. lol thanks again -Ron
  • Been working with CQRS and mediatr for years now, and from my experience it generally makes complex systems more complex. The need for CQRS or mediatr is generally not needed but many devs use it everywhere because its a shiny new pattern.
  • @sayedraminSadat
    Learned amazing staff today. Thank you Tim. I would love to see part 2 with advance MediatR implanted in complex application.
  • @RaihanTaher
    Thanks Tim for explaining things so clearly. You made the learning experience easy. Keep up the good work.
  • Tim, you did another excellent job breaking and explaining a topic that has challenged developers new to this tool and some of these concepts. Well done!
  • Hi, Tim. Great explanation! I have seen other developers getting a mess to explain clearly. How always your explanations bring us enlightenment. Thanks.
  • @nadervaghari51
    wow! I really enjoyed watching this wonderful course. I appreciate the way you teaching and rectifying the problems. Thanks Tim 👍🙏
  • @fadidib8516
    Thx for showing both the record and the class way, easier to understand this way.
  • @roaba3581
    Easily the most understandable explanation I have seen. Totally worth to watch the 1,5 hours instead of a few shorter vids that don't really deliver the whole picture.
  • @misterwoody_
    Many thanks Tim. Finally a video that covered reducing the dependency injection overload I was interested in, and how to put controllers on a diet. All the best.
  • @cymrucoder
    Incredibly useful video. We're refactoring an existing API at my work using the Mediator Pattern in the coming weeks, and this has introduced the topic to me so well! Keep up the amazing work.
  • @LuisBragagnolo
    Tim, you are the best!!! You explain complicated topics very simple! Thanks!
  • @ericwagner2307
    I loved the whiteboarding at the beginning with the gradual transition into code. Walking away from this one feeling very comfortable reviewing a codebase using MediatR. Thank you as always Tim!
  • @runtimmytimer
    Great timing. I just started a project that uses MediatR. Pretty cool stuff. Nice job on the explanation as well. They've implemented a generic handler class GenericHandler that abstracts away all the handler implementations. Interesting approach.