Integrating localization in validation frameworks
In Chapter 6, Exploring Validation and Mapping, we talked about how to integrate validation into a minimal API project. We learned how to use the MiniValidation
library, rather than FluentValidation
, to validate our models and provide validation messages to the callers. We also said that FluentValidation
already provides translations for standard error messages.
However, with both libraries, we can leverage the localization support we have just added to our project to support localized and custom validation messages.
Localizing validation messages with MiniValidation
Using the MiniValidation
library, we can use validation based on Data Annotations with minimal APIs. Refer to Chapter 6, Exploring Validation and Mapping, for instructions on how to add this library to the project.
Then, recreate the same Person
class:
public class Person { [Required] [MaxLength...