FluentValidation Integration

ABP Validation infrastructure is extensible. Volo.Abp.FluentValidation NuGet package extends the validation system to work with the FluentValidation library.

Installation

It is suggested to use the ABP CLI to install this package.

Using the ABP CLI

Open a command line window in the folder of the project (.csproj file) and type the following command:

  1. abp add-package Volo.Abp.FluentValidation

Manual Installation

If you want to manually install;

  1. Add the Volo.Abp.FluentValidation NuGet package to your project:

    1. Install-Package Volo.Abp.FluentValidation
  2. Add the AbpFluentValidationModule to the dependency list of your module:

  1. [DependsOn(
  2. //...other dependencies
  3. typeof(AbpFluentValidationModule) //Add the FluentValidation module
  4. )]
  5. public class YourModule : AbpModule
  6. {
  7. }

Using the FluentValidation

Follow the FluentValidation documentation to create validator classes. Example:

  1. public class CreateUpdateBookDtoValidator : AbstractValidator<CreateUpdateBookDto>
  2. {
  3. public CreateUpdateBookDtoValidator()
  4. {
  5. RuleFor(x => x.Name).Length(3, 10);
  6. RuleFor(x => x.Price).ExclusiveBetween(0.0f, 999.0f);
  7. }
  8. }

ABP will automatically find this class and associate with the CreateUpdateBookDto on object validation.

See Also