Validating options using FluentValidation
In this project, we validate options classes using FluentValidation. FluentValidation is a popular open-source library that provides a validation framework different from data annotations. One of the primary advantages of FluentValidation is that it allows encapsulating validation rules in another class than the one being validated. That makes the validation logic easier to test and more explicit than depending on metadata added by attributes. We explore FluentValidation more in Chapter 17, Getting Started with Vertical Slice Architecture, but that should not hinder you from following this example.
The name of the project in the source code is OptionsValidationFluentValidation
.
Here, I want to show you how to leverage a few patterns we’ve learned so far to implement this ourselves with only a few lines of code. In this micro-project, we leverage:
- Dependency injection
- The Strategy design pattern ...