Your problem is that ValidationAttributeAdapterProvider
, which is the default implementation of IValidationAttributeAdapterProvider
by default, only checks certain types. Thus, the use of custom implementations leads to the absence of "adapter providers", which leads to the absence of data attributes.
Decision. Provide your own implementation of IValidationAttributeAdapterProvider
, which can redirect to the default implementation for non-standard materials ...
public class CustomValidationAttributeAdapterProvider : IValidationAttributeAdapterProvider { private IValidationAttributeAdapterProvider innerProvider = new ValidationAttributeAdapterProvider(); public IAttributeAdapter GetAttributeAdapter(ValidationAttribute attribute, IStringLocalizer stringLocalizer) { if (attribute == null) throw new ArgumentNullException(nameof(attribute)); var type = attribute.GetType(); if (type == typeof(CustomRequiredAttribute)) return new RequiredAttributeAdapter((RequiredAttribute)attribute, stringLocalizer); return innerProvider.GetAttributeAdapter(attribute, stringLocalizer); } }
... and register it as a single.
services.AddSingleton<IValidationAttributeAdapterProvider, CustomValidationAttributeAdapterProvider>();
source share