Do I Need MediatR in Vertical Slice Architecture?

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ก.ย. 2024
  • ⭐️ Use the coupon code GUITDD to get a 20% discount course on my new TDD course: dometrain.com/...
    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 TH-cam 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/gsf...
    Visit my blog: gsferreira.com
    #dotnet #csharp

ความคิดเห็น • 12

  • @krccmsitp2884
    @krccmsitp2884 9 หลายเดือนก่อน +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 8 หลายเดือนก่อน +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 11 หลายเดือนก่อน +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  10 หลายเดือนก่อน +6

      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.

  • @jorgepedraza1275
    @jorgepedraza1275 9 หลายเดือนก่อน +1

    Any repo related with this video? 🤔

    • @gui.ferreira
      @gui.ferreira  9 หลายเดือนก่อน

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

  • @foonlam7134
    @foonlam7134 11 หลายเดือนก่อน

    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  11 หลายเดือนก่อน

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

    • @foonlam7134
      @foonlam7134 11 หลายเดือนก่อน

      @@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 5 หลายเดือนก่อน

      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

  • @AboutCleanCode
    @AboutCleanCode 11 หลายเดือนก่อน +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? 😉➡th-cam.com/video/JGgeoB-tXJw/w-d-xo.html

    • @gui.ferreira
      @gui.ferreira  11 หลายเดือนก่อน +1

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