Whitelist validation using the FluentValidation library
Most web developers may want to decouple the validation rules from their models and prefer the solution to be written in a unit test-friendly way. You may wish to create your own library that performs whitelisting validation or opt to use a popular and easy-to-use third-party library such as FluentValidation
, which has excellent validation features.
Getting ready
Using Visual Studio Code, open the sample Online Banking app folder at \Chapter01\input-validation-fluentvalidation\before\OnlineBankingApp
.
How to do it…
Let's take a look at the steps for this recipe:
- Launch Visual Studio Code and open the starting exercise folder by typing the following command:
code .
- Navigate to Terminal | New Terminal in the menu or simply press Ctrl + Shift + ' in Visual Studio Code.
- Type the following command to install the
FluentValidation
package in your project:dotnet add package FluentValidation
...