Custom FluentValidation translations for most built-in validators. BaseValidationApiController implemented with common error responses. Return ErrorModel with ModelState fields errors and with array of custom errors.
Packed as two NuGet packages. Core project with translations and AspNetCore project:
- Add code below in your Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services
.AddControllers(configure =>
{
configure.Filters.Add(typeof(ValidateModelActionFilter));
})
// Fluent validation
.AddFluentValidation(fv =>
{
// Register fluent validation as only validation library that executes
fv.DisableDataAnnotationsValidation = true;
fv.ImplicitlyValidateChildProperties = true;
fv.RegisterValidatorsFromAssemblyContaining<IValidatorResult>();
fv.RegisterValidatorsFromAssemblyContaining<Startup>();
});
// Fluent validation localization
// https://fluentvalidation.net/localization
ValidatorOptions.Global.LanguageManager = new ApiEnglishLanguageManager();
ValidatorOptions.Global.LanguageManager.Culture = new CultureInfo("en");
}
- Extend ApiEnglishLanguageManager with translations for your custom validators.