I'm using ASP.NET Core, with the built-in container.
Registration is supposed to be done like so:
services
.AddMvc()
.AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining<Startup>())
This automatically 1) configures FluentValidation, and 2) registers all validators found in the assembly.
But I want to register my validators manually. How do I do that?
Validation attributes let you specify validation rules for model properties. We can create custom validation attributes, create a class that inherits from ValidationAttribute, and override the IsValid method. Here is the code. The IsValid method accepts an object named value, which is the input to be validated.
FluentValidation is a . NET library for building strongly-typed validation rules. FluentValidation 11 supports the following platforms: . NET Core 3.1.
// must first setup FV
services
.AddMvc()
.AddFluentValidation(fv => {});
// can then manually register validators
services.AddTransient<IValidator<Foo>, FooValidator>();
services.AddTransient<IValidator<Bar>, BarValidator>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With