Edit

ASP0038: [ValidatableType] should not be used without a call to AddValidation

Value
Rule ID ASP0038
Category Usage
Severity Warning

Cause

The ValidatableTypeAttribute attribute is used in a project that doesn't call AddValidation.

Rule description

[ValidatableType] has no effect unless the current project calls AddValidation. The validation source generator only discovers types in the project that contains the AddValidation call.

How to fix violations

Call AddValidation on the service collection in the project that declares the validatable type:

builder.Services.AddValidation();

For a class library, provide a public service-registration method that calls AddValidation in the library project:

public static IServiceCollection AddOrderValidation(
    this IServiceCollection services)
{
    return services.AddValidation();
}

For more information, see Register validation in multi-assembly apps.