Consistent Response Validation - Invalid Value for types & Business Rules in Web API
Fluent validation is a great library to perform validation on objects. Integrating fluent validation in .net core is very simple and minimal steps are described along with a way to make validation response consistent be it binding error or business validation error. Steps 1. Add a reference to NuGet package <PackageReference Include="FluentValidation.AspNetCore" Version="8.4.0" /> Adding sample validator Person Validator 3. Validating Object Validating Object This works fine and the correct error message is displayed. Fluent Validation Error Message response However, consider the request where Date of Birth of person is passed as an invalid date. In this case, controller method gets null as input because of invalid type value during the model biding phase. By default below error message is thrown if model state is validated in the controller method Default Model State Error In t...