ABP Validation infrastructure is extensible. Volo.Abp.FluentValidation NuGet package extends the validation system to work with the FluentValidation library.
It is suggested to use the ABP CLI to install this package.
Open a command line window in the folder of the project (.csproj file) and type the following command:
abp add-package Volo.Abp.FluentValidation
If you want to manually install;
-
Add the Volo.Abp.FluentValidation NuGet package to your project:
Install-Package Volo.Abp.FluentValidation
-
Add the
AbpFluentValidationModule
to the dependency list of your module:
[DependsOn(
//...other dependencies
typeof(AbpFluentValidationModule) //Add the FluentValidation module
)]
public class YourModule : AbpModule
{
}
Follow the FluentValidation documentation to create validator classes. Example:
public class CreateUpdateBookDtoValidator : AbstractValidator<CreateUpdateBookDto>
{
public CreateUpdateBookDtoValidator()
{
RuleFor(x => x.Name).Length(3, 10);
RuleFor(x => x.Price).ExclusiveBetween(0.0f, 999.0f);
}
}
ABP will automatically find this class and associate with the CreateUpdateBookDto
on object validation.