Quickstart

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

See Fluent Validation: Creating your first validator for more detailed information

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);

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

Last updated

Was this helpful?