Do I Need MediatR in Vertical Slice Architecture?

Sdílet
Vložit
  • čas přidán 23. 10. 2023
  • ⭐️ Use the coupon code GUITDD to get a 20% discount course on my new TDD course: dometrain.com/course/from-zer...
    Is MediatR a must-have when implementing Vertical Slice Architecture?
    💎 Be a Patreon to get the source code: / gsferreira
    🚨 KEY LINKS
    🤝 Support me on Patreon (and get access to source code) here: / gsferreira
    👋 HEY FRIEND
    If you're new to my Channel, my name is Guilherme, but you can call me Gui if Portuguese pronunciation is not your thing.
    I see myself as a Minimalist Software Craftsman. That says a lot of what I talk about here.
    So, why this CZcams channel? To share with you to simplify your life as a Developer through knowledge, technology, and practices.
    If you are into those things as I do, don't forget to subscribe for new videos.
    🔗 GET IN TOUCH
    LinkedIn: / gferreira
    Twitter: / gsferreira
    GitHub: github.com/gsferreira
    Visit my blog: gsferreira.com
    #dotnet #csharp
  • Věda a technologie

Komentáře • 12

  • @krccmsitp2884
    @krccmsitp2884 Před 6 měsíci +5

    When you don't need multiple different pipelines, applying the Template Method pattern to your handlers is a good alternative to MediatR.

  • @anatolia23
    @anatolia23 Před 5 měsíci +1

    I'm surprised that the majority of developers still use reflection-based libraries. There is a powerful concept called 'Source Generator' in C#, and many libraries already use it, such as Mediator and Mapperly. Just use them and discover performance gain!

  • @iliyan-kulishev
    @iliyan-kulishev Před 8 měsíci +1

    What can be an argument for NOT using MediatR, even if you do VSA and need pipeline behavior for your handlers?
    I've heard people say that performance suffers due to the indirection and handler discovery done via reflection.

    • @gui.ferreira
      @gui.ferreira  Před 7 měsíci +5

      Performance can be a reason, however, not to the point that it's not a concern for 95% of the applications for sure.
      To me, the biggest reason is the simplicity.
      Bringing patterns that are not needed is adding complexity to the design.

  • @foonlam7134
    @foonlam7134 Před 8 měsíci

    Hi Gui, I have a controller method that receives a process message request and calls many services to do many things. if I implement a mediator handler how will I put this code in a handler. Videos only show the simple method that does only 1 thing and not one that needs to call many services to read and write data during the processing. Can you help?

    • @gui.ferreira
      @gui.ferreira  Před 8 měsíci

      Hi! I think I can record a video on that. Do you mind sharing which business problem are you solving?

    • @foonlam7134
      @foonlam7134 Před 8 měsíci

      @@gui.ferreira I'm trying to process a message received from an efpos terminal for purchase of a product. There are multiple validations and calculations eg the discount we have to give based on the product, then we have to call external apis to update the balance of the credit card and then on success we gave to create the transaction into the database and update the user's account as well as send an acknowledgement to the terminal of the success or failure of the purchase

    • @abhinavkapoor321
      @abhinavkapoor321 Před 2 měsíci

      One possibility is to register all handlers . And you can find the handler using IServiceProvider in Controller.
      The problem is that now your controller knows who is the handler, this is hidden with MediatR

  • @jorgepedraza1275
    @jorgepedraza1275 Před 6 měsíci +1

    Any repo related with this video? 🤔

    • @gui.ferreira
      @gui.ferreira  Před 6 měsíci

      Hi! Yes. You can grab it as a Patron: patreon.com/gsferreira

  • @AboutCleanCode
    @AboutCleanCode Před 8 měsíci +2

    I really like your recommendation to start simple and to not marry a framework or library right from the beginning of the project. 👍Of course battle proven libraries can give a lot of benefits but we should always make a conscious decision whether those benefits are actually needed - because benefits never come without disadvantages, right? 😉➡czcams.com/video/JGgeoB-tXJw/video.html

    • @gui.ferreira
      @gui.ferreira  Před 8 měsíci +1

      As it's common to say: "it depends"