MediatR Validation and the Chain of Responsibility Pattern

Поделиться
HTML-код
  • Опубликовано: 7 фев 2025
  • MediatR, Validation, and the Chain of Responsibility Pattern
    Download the source code:
    mailchi.mp/ard...
    Hey everyone, I'm Steve Smith aka ardalis, of NimblePros!
    In this video we take a look at how to pull validation out of our Web/UI layer and move it closer to our business/domain layer. We're using CQRS and MediatR with Clean Architecture to implement the Chain of Responsibility Pattern. The actual validation is using FluentValidation.
    Links
    github.com/ard...
    github.com/jbo...
    github.com/Flu...
    github.com/ard...
    • When To Validate and W... (When to Validate and When to Throw Exceptions?)
    Check out my courses:
    ardalis.com/tr...
    www.pluralsigh...
    Consulting and Training: NimblePros.com and @nimblepros
    Developer Group Mentoring: devBetter.com
    Free Weekly Email Tips:
    ardalis.com/tips/
    If you read this far, I hope you liked the video and consider subscribing to my channel!
    Find me:
    ardalis.com
    / ardalis
    github.com/ard...
    / stevenandrewsmith
    bsky.app/profi...
    #dotnet #deviq #ardalis #nimblepros #visualstudio #csharp #designpatterns #nuget #cleancode #validation #fluentvalidation #result #cleanarchitecture #mediatr #chainofresponsibility

Комментарии • 17

  • @fizmhd
    @fizmhd Год назад +1

    thanks for making videos, have been using your libraries, its great to see that you are on RUclips.

    • @Ardalis
      @Ardalis  11 месяцев назад

      Glad you like them!

  • @joshuawilliams8230
    @joshuawilliams8230 7 месяцев назад +1

    Your SOLID course on Pluralsight is so good! I also love your DDD course with Julie Lerman

    • @Ardalis
      @Ardalis  6 месяцев назад +1

      Thanks so much!

  • @rezaabolhasanzadeh6845
    @rezaabolhasanzadeh6845 Год назад +1

    tnx Steve . I love your content and way of teaching . I'm surprised your channel has few subs . please be more active on youtube . your knowledge is really usefull

    • @Ardalis
      @Ardalis  Год назад

      Thanks! Aiming for weekly videos; we’ll see how it goes.

    • @Ardalis
      @Ardalis  Год назад

      Thanks! Aiming for weekly videos; we’ll see how it goes.

  • @coderider3022
    @coderider3022 Год назад +2

    Yip, definitely use it with a fluent result return type (validation error mapped to reason) and I return this as a failure instead of calling next.

    • @Ardalis
      @Ardalis  11 месяцев назад

      Agreed.

  • @pavelernestonavarroguerrer7871
    @pavelernestonavarroguerrer7871 Год назад +1

    Thanks a lot! An excelent and practical use of the behaviors!

    • @Ardalis
      @Ardalis  11 месяцев назад

      Glad you enjoyed it!

  • @evilroxxx
    @evilroxxx 3 месяца назад

    Hi Ardalis, love the segment. Do you think it would make sense to add fluent validation on every step sort of like an anti corruption layer within the layers of the clean architecture?

    • @Ardalis
      @Ardalis  3 месяца назад

      I aim to do validation at the UI and/or app services (use cases) layer, and then use guard clauses and exceptions mainly in my domain modal. I have a video on *why* I make that distinction here: ruclips.net/video/dpPcnAT7n7M/видео.html&ab_channel=Ardalis

  • @herewegotoday
    @herewegotoday 9 месяцев назад

    I currently use the template method pattern for ensuring multiple features always create an audit log for the task. Would the chain of responsibility pattern be better suited for such a thing? It certainly seems more elegant.

    • @Ardalis
      @Ardalis  9 месяцев назад +1

      It would almost certainly require less code and would eliminate inheritance, which usually simplifies designs. I'd say it's worth trying it and then you can assess which you prefer.

  • @mesutdemirci7933
    @mesutdemirci7933 11 месяцев назад +1

    Thanks a lot!

    • @Ardalis
      @Ardalis  11 месяцев назад +1

      You're welcome!