Have been using your FluentValidation component and note that it indicates there are issues when calling async validators. I had tried following two versions of an asynchronous rule that verifies if an email address is already registered and thus unavailable. The first causes browser to lock up, whilst second is executed and Failure added to context - though not displayed in UI. PS.
public class RegisterRequestValidator : AbstractValidator<RegisterRequest>
{
public RegisterRequestValidator(AuthService _svc)
{
// this rule causes browser lockup so not used
RuleFor(p => p.EmailAddress).MustAsync(async (email, cancellation) => {
bool available = await _svc.VerifyEmailAvailableAsync(email);
return !available;
}).WithMessage("EmailAddress is already Registered");
// this rule is executed but validation message is not displayed in UI
RuleFor(p => p.EmailAddress).NotEmpty().EmailAddress()
.Custom(async (email, context) => {
var available = await _svc.VerifyEmailAvailableAsync(email);
if (!available)
{
context.AddFailure("EmailAddress", "Email has already been registered. Please use another.");
}
}
);
}
}
<EditForm Model="RegisterModel" OnValidSubmit="HandleRegistration">
<FluentValidator />
<div class="form-group">
<label for="email">Email address</label>
<InputText Id="email" class="form-control" @bind-Value="RegisterModel.EmailAddress" />
<ValidationMessage For="@(() => RegisterModel.EmailAddress)" />
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</EditForm>