I see how you can re-use a validator for Complex Properties and Collections, but how will it work when the reference is bi-directional? Will the example below produce an infinite loop, and if so what is the best way to handle this?
public class Customer {
public string Name { get; set; }
public Address Address { get; set; }
}
public class Address {
public string Line1 { get; set; }
public string Line2 { get; set; }
public string Town { get; set; }
public string County { get; set; }
public string Postcode { get; set; }
public Customer Customer { get; set; }
}
public class AddressValidator : AbstractValidator<Address> {
public AddressValidator() {
RuleFor(address => address.Postcode).NotNull();
RuleFor(address => address.Customer).SetValidator(new CustomerValidator());
//etc
}
}
public class CustomerValidator : AbstractValidator<Customer> {
public CustomerValidator() {
RuleFor(customer => customer.Name).NotNull();
RuleFor(customer => customer.Address).SetValidator(new AddressValidator());
}
}