ValidationAttributeFormatterRegistry Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Registry of IValidationAttributeFormatter factories keyed by ValidationAttribute type. Used by the validation localization pipeline to format localized error message templates with attribute-specific arguments.
public ref class ValidationAttributeFormatterRegistry sealed
public sealed class ValidationAttributeFormatterRegistry
type ValidationAttributeFormatterRegistry = class
Public NotInheritable Class ValidationAttributeFormatterRegistry
- Inheritance
-
ValidationAttributeFormatterRegistry
Remarks
Resolution order:
- If the attribute implements IValidationAttributeFormatter itself (self-formatting), it is returned directly.
- If a factory is registered for the attribute's type via AddFormatter<TAttribute>(Func<TAttribute,IValidationAttributeFormatter>), it is used to create a formatter.
- Otherwise,
nullis returned, indicating that no attribute-specific formatter is available.
Built-in formatters for standard validation attributes (such as RangeAttribute, MinLengthAttribute, StringLengthAttribute, etc.) are registered automatically. Later registrations for the same attribute type replace earlier ones.
builder.Services.AddValidationLocalization(options =>
options.AttributeFormatters.AddFormatter<CreditCardAttribute>(
attribute => new CreditCardAttributeFormatter(attribute)));
Constructors
| Name | Description |
|---|---|
| ValidationAttributeFormatterRegistry() |
Creates a new instance of ValidationAttributeFormatterRegistry with built-in formatters for standard validation attributes. |
Methods
| Name | Description |
|---|---|
| AddFormatter<TAttribute>(Func<TAttribute,IValidationAttributeFormatter>) |
Registers a formatter factory for the specified validation attribute type. Later registrations for the same type replace earlier ones. |
| GetFormatter(ValidationAttribute) |
Returns an IValidationAttributeFormatter for the specified |