public Validator(IUserContext userContext, ITransactionRepository repository) { RuleFor(command => command.AccountId) .NotNull() .NotEmpty() .MustAsync(async(id, cancellation) => (await repository.AccountExists(id, userContext.UserId, cancellation))) .WithMessage(x => $"Account '{x.AccountId}' does not exists.") .WithErrorCode("NotExistsValidator"); RuleFor(command => command.CategoryId) .NotNull() .NotEmpty() .MustAsync(async(id, cancellation) => (await repository.CategoryExists(id, userContext.UserId, cancellation))) .WithMessage(x => $"Category '{x.CategoryId}' does not exists.") .WithErrorCode("NotExistsValidator"); RuleFor(command => command.Date).NotEmpty(); RuleFor(command => command.Amount).GreaterThan(0); }