bullseye-arrowQuickstart

Get started with using Waystone.Monads.FluentValidation in under a minute.

1

Install the library

dotnet add package Waystone.Monads.FluentValidation
2

Create a validator

circle-info
record UserInput(int Range, string Search);
class UserInputValidator : AbstractValidator<UserInput> 
{
    public UserInputValidator()
    {
        RuleFor(x => x.Range).GreaterThan(0);
        RuleFor(x => x.Search).NotEmpty();
    }
}
3

Validate

UserInput input = new(1, "bob");
UserInputValidator validator = new();
Result<UserInput, ValidationErr> result = input.Validate(validator);
// or
Result<UserInput, ValidationErr> result = await input.ValidateAsync(validator, cancellationToken);
circle-info

See Waystone.Monads to learn how to work with a Result

Last updated

Was this helpful?