The Catalog.Domain project also owns the validation logic of our request models. In this section, we will see how to implement the request validation logic part, which will be also used by our controllers in order to validate the incoming data. Here, I usually rely on the FluentValidation package, which provides a really readable way to perform validation checks on every type of object and data structure.
In order to add the FluentValidation package to our Catalog.Domain project, we can execute the following commands in the project folder:
dotnet add package FluentValidation
dotnet add package FluentValidation.AspNetCore
The FluentValidation package exposes the AbstractValidation class, which can be extended to implement our custom validation criteria for a request model class:
//Requests/Item/Validators/AddItemRequestValidator.cs
using FluentValidation...