lundi 4 décembre 2023

DB calls in FluentValidator class in DDD implemetation

We are implementing DDD in our project and we are using fluent for data validation.

FluentDataValidation class has some service calls(like diff db calls and AD call) for validating data.

Is this valid in DDD design to have service layer called from Validator class?

        public PublicValidator(IMetadataService metadataService)
    {
        this.When(status => status.IsStatusInComplete(), () =>
        {
            this.RulesWhenStatusIsInComplete(metadataService);
        })
        .Otherwise(() =>
        {
            this.RulesWhenStatusIsOtherThanIncomplete(metadataService);
        });

        this.RuleFor(s => s.Employers)
        .Must((r, p) => !r.people())
        .WithMessage(PeopleMessages.Dates);

        this.When(s => s.Employers != null && s.Employers.Count > 0 && !s.HasDefault, () =>
        {
            this.RuleForEach(s => s.Employers).ChildRules(a =>
            {
                a.RuleFor(s => s.Einperp)
                .NotEmpty()
                .Must(o => (metadataService.GetEmployerByEinperp(o) != null))
                .WithMessage(Constants.IncorrectMetadata);}

Aucun commentaire:

Enregistrer un commentaire