-
Notifications
You must be signed in to change notification settings - Fork 17
Added support for calling TryValidateModel #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
5654e44
to
945cab4
Compare
…erted into AggregateException
736f137
to
1daba17
Compare
this.disableBuiltInModelValidation = disableBuiltInModelValidation; | ||
} | ||
|
||
public override bool Validate(ModelMetadata? metadata, string? key, object? model, bool alwaysValidateAtTopLevel) | ||
{ | ||
// If built in model validation is disabled return true for later validation in the action filter. | ||
return disableBuiltInModelValidation || base.Validate(metadata, key, model, alwaysValidateAtTopLevel); | ||
bool isBaseValid = disableBuiltInModelValidation || base.Validate(metadata, key, model, alwaysValidateAtTopLevel); | ||
return ValidateAsync(isBaseValid, key, model).GetAwaiter().GetResult(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@icnocop not sure about this one, won't this result in deadlocks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -9,19 +9,29 @@ public class FluentValidationAutoValidationObjectModelValidator : ObjectModelVal | |||
{ | |||
private readonly bool disableBuiltInModelValidation; | |||
|
|||
public FluentValidationAutoValidationObjectModelValidator(IModelMetadataProvider modelMetadataProvider, IList<IModelValidatorProvider> validatorProviders, bool disableBuiltInModelValidation) | |||
public FluentValidationAutoValidationObjectModelValidator( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@icnocop keep existing formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in fd34ec6
Thank you.
IModelValidatorProvider validatorProvider, | ||
ValidatorCache validatorCache, | ||
IModelMetadataProvider metadataProvider, | ||
ValidationStateDictionary? validationState) | ||
{ | ||
return new FluentValidationAutoValidationValidationVisitor(actionContext, validatorProvider, validatorCache, metadataProvider, validationState, disableBuiltInModelValidation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@icnocop keep existing formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in fd34ec6
Thank you.
{ | ||
public static class FluentValidationHelper | ||
{ | ||
public static async Task<ValidationResult?> ValidateWithFluentValidationAsync( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@icnocop this method feels kinda hacky by taking a IServiceProvider as an argument, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What else do you recommend?
IServiceProvider
is needed to dynamically get the validator based on the type of the model.
Fixes #53