Hello,
I created a validator to specifically validate a User Email within many UserModels:
```
public class UserEmailValidator : AbstractValidator<String> {
public UserEmailValidator(Func<IDispatcher> dispatcher, Func<IWebUser> user) {
RuleFor(x => x)
.EmailAddress().WithMessage("The email is invalid")
.Must(x => dispatcher().Send<ValidateUserEmailReply>(new ValidateUserEmailQuery(new Guid(user().Identity.GetUserId()), x)).Valid).WithMessage("The email is unavailable");
}
}
```
Then in a User Model Validator I have:
```
RuleFor(x => x.Email)..SetValidator(new UserEmailValidator());
```
But this does not compile because the UserEmailValidator does not have an empty constructor.
Is there a way to attach this validator and use it without passing the dispatcher and webuser from the parent validator?
What approach would you use?
Thank You,
Miguel
Comments: Hi No - you'd need to take these as arguments to the parent validator too.
I created a validator to specifically validate a User Email within many UserModels:
```
public class UserEmailValidator : AbstractValidator<String> {
public UserEmailValidator(Func<IDispatcher> dispatcher, Func<IWebUser> user) {
RuleFor(x => x)
.EmailAddress().WithMessage("The email is invalid")
.Must(x => dispatcher().Send<ValidateUserEmailReply>(new ValidateUserEmailQuery(new Guid(user().Identity.GetUserId()), x)).Valid).WithMessage("The email is unavailable");
}
}
```
Then in a User Model Validator I have:
```
RuleFor(x => x.Email)..SetValidator(new UserEmailValidator());
```
But this does not compile because the UserEmailValidator does not have an empty constructor.
Is there a way to attach this validator and use it without passing the dispatcher and webuser from the parent validator?
What approach would you use?
Thank You,
Miguel
Comments: Hi No - you'd need to take these as arguments to the parent validator too.