I have a model that implements IValidatableObject and I need to localize ValidationResults, how can I achieve this correctly?
Currently, I came up with the IValidatableObject.Validate method, which looks like this:
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { var stringLocalizer = validationContext.GetService(typeof(IStringLocalizer<MyModel>)) as IStringLocalizer<MyModel>;
What I'm doing here is finding an instance of IStringLocalizer using the ValidationContext.GetService method.
This approach works, but my main problem is that I'm not quite sure if this is correct, because I need to rely on a service locator to get IStringLocalizer
source share