-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FluentValidation with Conventional Controllers? #21971
Comments
|
I'm using version 9.0.3 In the solution, project HttpApi, i´ve created a controller, and endpoint input class and the the validator.
public class CreateUserDto
{
public string Name {get;set;}
}
public class CreateUserValidator : AbstractValidator<CreateUserDto>
{
public CreateUserValidator()
{
RuleFor(x => x.Name )
.NotEmpty()
.WithMessage("The property {PropertyName} is required");
}
}
[ApiVersion("1.0", Deprecated = false)]
[ApiController]
[ControllerName("user")]
[Route("api/user")]
public class UserController : MyDemoController
{
[HttpPost()]
public virtual async Task<IActionResult> CreateUser(FromBody] CreateUserDto input)
{
// do something to create the user
return Ok();
}
}
Those are the steps. But only worked for me if i follow the official documentation of FluenValidation. And in the module ConfigureServices method, execute that:
|
hi @lommez Can you share a project on Github? Thanks. |
Looks like FluentValidation doesnt work with Asp. Net conventional controllers.
There is something else that i must do to make it work?
Or should i and use the official approach of FluentValidation to setup correctly?
Thanks
The text was updated successfully, but these errors were encountered: