Forget Everything You Know About MediatR!

Поділитися
Вставка
  • Опубліковано 25 чер 2024
  • MediatR is one of the most popular library for .NET developers. It latest release, however, came out with some important breaking changes. In this video I go through those changes that might affect your day to day work if you want to upgrade to MediatR 12 or if you are starting a brand new project.
    #dotnet #csharp #dotnetdeveloper #programming
    Join this channel to get source code access and other perks:
    / @codewrinkles
    Also follow me here (especially if you are a self taught developer):
    ✅My other channel: / @danpatrascutech
    ✅Facebook: / danpatrascutech
    ✅Instagram: / danpatrascutech
    ✅TikTok: / danpatrascutech
    ✅Newsletter: www.danpatrascu.tech/
    Content
    1. Intro: 00:00
    2. The MediatR package: 00:51
    3. MediatR service registration: 02:40
    4. "Void" returning request handlers: 05:00
    5. Parallel notification handler execution: 07:00
    6. Upgrading to MediatR 12: 10:02
    My setup:
    Camera - Canon EOS M50 Mark II: amzn.to/3SJxS4d
    Lav mic - Rode Lavalier GO Professional: amzn.to/3mmZS1B
    Condenser mic - Shure SM7B: amzn.to/3JaqjQN
    Audio console - Rodecaster PRO II: amzn.to/3KTVMIg
    Laptop - Dell Latitude: amzn.to/3KV4SEW
    Monitors - Benq 27 inch: amzn.to/3JbM6aU
    Lights - 2x Godox SL-60W: amzn.to/3KV3qCj
  • Наука та технологія

КОМЕНТАРІ • 25

  • @georget10i
    @georget10i Рік тому +2

    I like the title of the video. It highlights precisely why you should not bother too much with remembering exact implementations and instead focus on truly understanding and grasping concepts. Concepts remain the same, but implementations change often. Thanks for another great tutorial, Dan!

  • @andersonhansen9542
    @andersonhansen9542 Рік тому +6

    MediatR is very nice, but there is always the question "Should I use it or not in production?"

    • @Codewrinkles
      @Codewrinkles  Рік тому +5

      I'm not sure how much you follow we on Twitter or LinkedIn, but I'm certainly that kind of guy that thinks adding a library to your project means addign technical debt. Which might be good or bad, depending how you plan to deal with this technical debt. Coming back to MediatR, I'd say it depends. In some projects I've used it. In some projects not. Where I find the most value in this library are pipeline behaviors, so if I think that in a project I'll make heavy use of this feature, then I prefer to use MediatR than to write similar functionality.

    • @manilladrift
      @manilladrift Рік тому +1

      ​@@Codewrinkles mind explaining why you think adding third party libraries to an enterprise project is adding technical debt?

    • @nove1398
      @nove1398 Рік тому +2

      @@manilladrift one reason is you will have to maintain that package. I have the same opinion , if you can get by without depending on anything external i prefer that way, but this is more so a personal agreement than a general guideline.

    • @Codewrinkles
      @Codewrinkles  Рік тому

      There are a lot of reasons like intellectual property (customers want to have IP over the code of their apps), library lock-in, potential unpredictable costs, security vulnerabilities and so on

    • @kabal911
      @kabal911 Рік тому +2

      @@nove1398 you also need to seriously weigh up that you might have just transferred that technical debt. A developer must now build it and maintain it. This build might not actually offer any business value.
      Very popular libraries are often battle tested by 100’s of thousands of developers.
      As with everything, it depends 👍🏻
      However, if you are not the one paying for the development, then i do not agree that “personal preference” is a valid reason. Licensing costs/restrictions, etc - absolutely.

  • @xelaksal6690
    @xelaksal6690 Рік тому

    Thanks for the video. This background music in my opinion fits most and don't interrupt the experience.

    • @Codewrinkles
      @Codewrinkles  Рік тому

      Thank you very much for watching and for the feedback.

  • @Forshen
    @Forshen 11 місяців тому +1

    Hi, i don't get the concept of the Request and the handler of it. Cause Mediatr has the Send function, passing a object, and 1 handler for handling that object. But why it is better compared to just calling a command/query directly?

  • @ramfattah211
    @ramfattah211 Рік тому

    Thanks. Amazing video.
    I have a video suggestion idea if it's alright: could you do video on inheritance and entity framework in regards creating models and registering them in DbContext class. Also how would we view different derived model in a blazor component and how would we return the derived model classes in the data access layer of the project?
    For example, do we need to do some sort of casting to view the derived class in a blazor server component?

    • @Codewrinkles
      @Codewrinkles  Рік тому +2

      Great suggestion. The topic of persistence strategy for inheritance trees is actually a very good one. I think the Blazor part would fit in a different video though. I'm considerin these ideas.Thanks for watching and commenting.

    • @ramfattah211
      @ramfattah211 Рік тому

      @@Codewrinkles Thank you so much for considering this. Looking forward to learning more c# from you 😊

  • @codewkarim
    @codewkarim Рік тому

    Imagine stopping the video at "Forget everything you know about MediatR".
    JK. Good video thanks!

  • @MrVarsium
    @MrVarsium Рік тому

    is this new version more performant then the "mediator" package? (its a bit aside of goal of this vid sorry)

    • @Codewrinkles
      @Codewrinkles  Рік тому +3

      I'll be honest with you and I'll say that I haven't run any benchmark against it so far. But that's a good idea and maybe something for a dedicated video. Thanks for watchin and for the comment.

    • @Codewrinkles
      @Codewrinkles  Рік тому +1

      Does it also support notifications and behaviors?

    • @kabal911
      @kabal911 Рік тому +2

      MediatR’s performance overhead is negligible compared to things that you would do in handlers like I/O. (microseconds vs milliseconds)
      If performance is a real consideration (which is IMO vastly overstated), then it is unlikely that MediatR would be a real candidate for a tool anyway.

  • @longuinni
    @longuinni 8 місяців тому

    I don't know why people need MediatR. I can do everything with DI and .net core features.

  • @user-uq5us4bp7p
    @user-uq5us4bp7p Рік тому +1

    Can you remove music please

    • @Codewrinkles
      @Codewrinkles  Рік тому +1

      Thank you for the feedback. I will take this into consideration.

    • @ramfattah211
      @ramfattah211 Рік тому +1

      I actually like the music.

  • @user-kg7if8ed6k
    @user-kg7if8ed6k Рік тому +1

    I've encountered an annoying problem when I created a project with dotnet 7 and used MediatR 12.0.1I configured MediatR in Program.cs as bellow :builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(Program).Assembly));
    and use it in the controller as bellow : public async Task AddCustomer([FromBody] CustomerInfo command) {
    await _mediator.Send(new AddCustomerCommand(command)); return StatusCode(201); }
    Apart from that I implementing Handler as bellow : private readonly ICustomerRepository _customerRepository; public AddCustomerCommandHandler(ICustomerRepository customerRepository) => _customerRepository = customerRepository; public async Task Handle(AddCustomerCommand request, CancellationToken cancellationToken) { await _customerRepository.AddCustomerAsync(request.customer); return; }
    and Command as :public record AddCustomerCommand(CustomerInfo customer) : IRequest;
    but encountered :No service for type 'MediatR.IRequestHandler has been registered.
    I googled that error and tried several things to configured MediatR in Program.cs but the result was the same.Could you please help me ?

    • @thomaswoods1365
      @thomaswoods1365 4 місяці тому

      I had the same experience. I CANNOT get MediatR 12 to work!