Customization & Extensibility – Updated Extension Point
IValidationMessageResolver
You can implement your own message resolution strategy by inheriting:
public interface IValidationMessageResolver
{
string? ResolveMessage(PropertyValidationInfo propertyInfo, ValidationAttribute attr);
}
By default, ValidationMessageResolver uses:
- propertyInfo.TargetModelType to locate the resource class
- Convention: PropertyName_AttributeType for message keys
- Fallback to [ErrorMessage] or default text
Custom resolvers can inject external providers, telemetry, or override formatting logic.
Register via DI:
services.AddSingleton<IValidationMessageResolver, MyCustomResolver>();
Add Custom Rules
Extend DataAnnotationsValidator with your own attributes:
public class MyCustomAttribute : ValidationAttribute
{
// Your logic here
}