Created
August 20, 2019 15:24
-
-
Save mattwcole/bd66fe39c1c6b34c83e2438acf4395db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvc() | |
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2) | |
.AddFluentValidation(config => | |
{ | |
config.RegisterValidatorsFromAssemblyContaining<FooValidator>(); | |
config.RunDefaultMvcValidationAfterFluentValidationExecutes = false; | |
}) | |
.ConfigureApiBehaviorOptions(options => | |
{ | |
options.InvalidModelStateResponseFactory = context => new BadRequestObjectResult(context.ModelState.SelectMany( | |
modelState => modelState.Value.Errors.Select(error => | |
new ClientError | |
{ | |
Item = modelState.Key, | |
Message = error.ErrorMessage | |
}))); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment