FluentValidation Integration
VCP Validation infrastructure is extensible. Verto.Vcp.FluentValidation NuGet package extends the validation system to work with the FluentValidation library.
Installation
It is suggested to use the VCP CLI to install this package.
Using the VCP CLI
Open a command line window in the folder of the project (.csproj file) and type the following command:
vcp add-package Verto.Vcp.FluentValidation
Manual Installation
If you want to manually install;
Add the Verto.Vcp.FluentValidation NuGet package to your project:
Install-Package Verto.Vcp.FluentValidation
Add the
VcpFluentValidationModule
to the dependency list of your module:
[DependsOn(
//...other dependencies
typeof(VcpFluentValidationModule) //Add the FluentValidation module
)]
public class YourModule : VcpModule
{
}
Using the FluentValidation
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);
}
}
VCP will automatically find this class and associate with the CreateUpdateBookDto
on object validation.