C# 10 - implementing Custom Validation Attributes Not Firing on Nested Objects Using FluentValidation
I'm writing unit tests and I'm a bit lost with I'm having trouble getting my custom validation attributes to work properly when validating nested objects using FluentValidation in a C# 10 application. I have a model with a nested object, and although the parent object is being validated correctly, the nested object validations are being skipped. Hereβs how my classes are set up: ```csharp public class Order { public int Id { get; set; } public Customer Customer { get; set; } } public class Customer { [Required(ErrorMessage = "Name is required")] public string Name { get; set; } [EmailAddress(ErrorMessage = "Email is not valid")] public string Email { get; set; } } ``` I created a validator for the `Order` class: ```csharp public class OrderValidator : AbstractValidator<Order> { public OrderValidator() { RuleFor(x => x.Customer) .NotNull() .SetValidator(new CustomerValidator()); } } public class CustomerValidator : AbstractValidator<Customer> { public CustomerValidator() { RuleFor(x => x.Name) .NotEmpty(); RuleFor(x => x.Email) .EmailAddress(); } } ``` When I call the validation, it seems like the `Customer` properties are not being validated at all. I invoke it like this: ```csharp var order = new Order { Customer = new Customer { Name = "", Email = "invalidemail" } }; var validator = new OrderValidator(); var result = validator.Validate(order); ``` I expected the validation to unexpected result because the `Name` is empty and the `Email` is invalid. However, the `ValidationResult` indicates successful validation with no errors. Iβve checked that the FluentValidation library is correctly set up in my project, and Iβm using version 10.0.0. Could anyone guide to figure out why the nested validation is not firing? Is there a specific configuration I might be missing or a best practice I should follow? Thanks! I'm open to any suggestions. Is there a better approach? For reference, this is a production service.