dotnet-starter-kit icon indicating copy to clipboard operation
dotnet-starter-kit copied to clipboard

Use mediatr validationbehavior iso aspnetcore automatic validation

Open fretje opened this issue 3 years ago • 3 comments

See https://github.com/fullstackhero/dotnet-webapi-boilerplate/issues/639

I started working on this, and adding the behavior itself is easy. I also had to add some code to the ExceptionMiddleware to properly handle the ValidationException. (I have totally replaced this with ProblemDetails middleware in my project... but that's for another PR..)

But the problem now is that not all calls go through mediatr. In particular the identity calls, but also the multitenancy calls. We're gonna have to route those through mediatr as well after all... That's why it's still a draft...

But anyone can pick this up if they like... It boils down to creating request handlers that simply forward to the services, and then using mediatr in the controller methods in stead of calling the service directly.

fretje avatar May 31 '22 13:05 fretje

In the mean time I've updated everything again to the latest version of fluentvalidation (and zymlabs.nswag.fluentvalidation). I've also made mediatr requests for CreateOrUpdateRole, UpdateRolePermissions and UpdateUserRequest.

Those were the main ones I needed ;-)

There's still some more that need to be done:

  • TokenRequest
  • CreateUserRequest
  • ChangePasswordRequest
  • ForgotPasswordRequest

fretje avatar Jul 03 '22 13:07 fretje

Where is IApplicationMarker in Infrastructure startup? I can't find it anywhere in the code. What package/pull request is it in?

curelom avatar Jul 05 '22 04:07 curelom

@curelom IApplicationMarker is a new type introduced in this PR. It is under Application/Common/Interfaces. It's used in AddInfrastructure to more easily register MediatR handlers and FluentValidation validators that are in the Application library.

fretje avatar Jul 05 '22 06:07 fretje