I read your article titled "Writing custom validation" and ran into some issues while learning it. I'd appreciate if you could clarify this.
One - Fact:
In the article, the methods passed to EditContext.OnValidationRequested and EditContext.OhFieldChanged both are async void methods:
async void ValidationRequested(object sender, ValidationRequestedEventArgs args)
{
ValidationMessageStore.Clear();
var validationContext =
new ValidationContext<object>(EditContext.Model);
ValidationResult result =
await Validator.ValidateAsync(validationContext);
AddValidationResult(EditContext.Model, result);
}
Two - Fact:
EditContext.Validate() is not asynchronous and won't await the async void delegates passed to EditContext.OnValidationRequested:
public bool Validate()
{
OnValidationRequested?.Invoke(this, ValidationRequestedEventArgs.Empty);
return !GetValidationMessages().Any();
}
Three - Problem:
I think, given the setup described, we won't have fluent validations occur by calling EditContext.Validate(), as the returned value simply indicates whether there are validation errors or not, and on the other hand there are high chances that validation errors will be added to the message stores after the Validate() has returned its value.
Am I missing anything? If the issue I described is valid, the FluentValidationValidator developed in this article can become a source of bugs.
I read your article titled "Writing custom validation" and ran into some issues while learning it. I'd appreciate if you could clarify this.
One - Fact:
In the article, the methods passed to
EditContext.OnValidationRequestedandEditContext.OhFieldChangedboth areasync voidmethods:Two - Fact:
EditContext.Validate()is not asynchronous and won'tawaittheasync voiddelegates passed toEditContext.OnValidationRequested:Three - Problem:
I think, given the setup described, we won't have fluent validations occur by calling
EditContext.Validate(), as the returned value simply indicates whether there are validation errors or not, and on the other hand there are high chances that validation errors will be added to the message stores after theValidate()has returned its value.Am I missing anything? If the issue I described is valid, the
FluentValidationValidatordeveloped in this article can become a source of bugs.