-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Hello,
I was a little disappointed when I upgraded from v6.2.1 to v7.0.3. I encountered with a breaking change that was introduced in v6.4 (March 3, 2017). It is not possible to pass NULL value into the validator anymore starting from v6.4. I don't know if it is by design or it is something that was not planned (sort of side-effect).
For example, I cannot have something like this:
public class CreateFolderRequestValidator : AbstractValidator<CreateFolderRequest>
{
public CreateFolderRequestValidator()
{
RuleFor(x => x).NotNull();
When(x => x != null, () =>
{
// Validation rules...
});
}
}
The ArgumentNullException is thrown when NULL is passed into the ValidateAndThrow method with the following message:
Value cannot be null. Parameter name: Cannot pass null model to Validate.
Before v6.4, I could check for NULL value in the validator, but now I have to do it EVERYWHERE outside of the validator. I need to write this extra check for NULL before every call to the ValidateAndThrow method which (to me) should really be up to the validator.
Please, consider this case. Please, make it possible to check for NULL inside of the validator so that no ArgumentNullException would be thrown. Or at least, it would be great if there would be a way to configure this behavior. Maybe, there could be some default behavior and this behavior could be changed in the validator's constructor like, for example, "AllowNullInstance = true" or something like this.
Thank you.