FluentValidation Introduction
Being able to consistently write validation rules in a standardized way in .NET is a neccessity. This is extremely important when accepting data from boundaries out of your control such as REST APIs or gRPC.
FluentValidation solves this need by allowing you to build strongly-typed validation rules for your.NET types.
Here is an example.
1 |
|
From the excellent documentation that accompanies FluentValidation:
- instantiate the validator object
- call the Validate method, passing in the object to validate
1 |
|
A simple inspection of the result IsValid property and accompanying Errors collection is all that it takes to ensure an object instance in a valid state.
We’ve barely scratched the surface here and in future blobs, I’ll share some more techniques that I like to use within my solutions.