I am trying to write validation rule for multiple string properties, to check whether they are unique.
so i made validator to check it.
_service method returns list of error codes, that correspond with properties which are not unique.
Now how can I get response message or several in accordance with returned result codes?
RuleFor(x => x.User)
.MustAsync(async (q, context, token) =>
{
var errors = await _service.CheckUserNameEmailExistsAsync(q.User.UserName, q.User.Email, token);
return !errors.Any();
}).WithMessage(...);
errorsexactly? I'd make a sub-validator for User. Then you can check uniqueness of each of it's properties and add a failure to the context if appropriate.