I have multiple async rules that requires the same API calls.
How can I avoid calling the same api twice in a single validation run?
public class ModelValidator : AbstractValidator<Model>
{
public ReservationDetailModelValidator(IApiClient api)
{
RuleFor(x => x.Amount)
.MustAsync(async (x, val) =>
{
var apiResult = api.Fetch(x.Id);
return apiResult.Value < value)
}).WithMessage("Validation rule 1");
.MustAsync(async (x, val) =>
{
var apiResult = api.Fetch(x.Id);
return apiResult.OtherProperty == x.OtherProperty)
}).WithMessage("Validation rule 2");
}
}
Should I use RootContextData, or override prevalidate?