Base solution for your next web application
Open Closed

FluentValidation #5567


User avatar
0
BlueBrackets created

I'm using the MVC core template and try to implement FluentValidation. I've installed the package Abp.FluentValidation and set the DependsOn attribute for the type AbpFluentValidationModule at the WebCoreModule class.

I've added the validator class below for the input class of a service but seems not to validate, any value for NumberOfUnits is valid.

class CreateOrEditUnitDtoValidator : AbstractValidator<CreateOrEditUnitDto>
    {
        public CreateOrEditUnitDtoValidator()
        {
            RuleFor(x => x.NumberOfUnits).GreaterThanOrEqualTo(10);
        }
    }

Do I miss something or is the fluent validation not working on services?


3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    The CreateOrEditUnitDtoValidator class should be public.

  • User Avatar
    0
    BlueBrackets created

    The validator class should be public, but the other thing is that the validator class should be placed in solutionname.Application project instead of the solutionname.Application.Shared where the dto's are located.

    After moving the validator class and making it public the validation is working, thanks for your help.

  • User Avatar
    0
    alper created
    Support Team

    thanks for the feedback