public DeleteTagAttachmentCommandValidator( IProjectValidator projectValidator, ITagValidator tagValidator, IRowVersionValidator rowVersionValidator) { CascadeMode = CascadeMode.Stop; RuleFor(command => command) .MustAsync((command, token) => NotBeAClosedProjectForTagAsync(command.TagId, token)) .WithMessage(command => $"Project for tag is closed! Tag={command.TagId}") .MustAsync(BeAnExistingTagAttachmentAsync) .WithMessage(command => "Tag and/or attachment doesn't exist!") .MustAsync((command, token) => NotBeAVoidedTagAsync(command.TagId, token)) .WithMessage(command => $"Tag is voided! Tag={command.TagId}") .Must(command => HaveAValidRowVersion(command.RowVersion)) .WithMessage(command => $"Not a valid row version! Row version={command.RowVersion}"); async Task <bool> NotBeAClosedProjectForTagAsync(int tagId, CancellationToken token) => !await projectValidator.IsClosedForTagAsync(tagId, token); async Task <bool> BeAnExistingTagAttachmentAsync(DeleteTagAttachmentCommand command, CancellationToken token) => await tagValidator.ExistsTagAttachmentAsync(command.TagId, command.AttachmentId, token); async Task <bool> NotBeAVoidedTagAsync(int tagId, CancellationToken token) => !await tagValidator.IsVoidedAsync(tagId, token); bool HaveAValidRowVersion(string rowVersion) => rowVersionValidator.IsValid(rowVersion); }