Fluent.Unions.FluentValidation
1.1.0
dotnet add package Fluent.Unions.FluentValidation --version 1.1.0
NuGet\Install-Package Fluent.Unions.FluentValidation -Version 1.1.0
<PackageReference Include="Fluent.Unions.FluentValidation" Version="1.1.0" />
<PackageVersion Include="Fluent.Unions.FluentValidation" Version="1.1.0" />
<PackageReference Include="Fluent.Unions.FluentValidation" />
paket add Fluent.Unions.FluentValidation --version 1.1.0
#r "nuget: Fluent.Unions.FluentValidation, 1.1.0"
#:package Fluent.Unions.FluentValidation@1.1.0
#addin nuget:?package=Fluent.Unions.FluentValidation&version=1.1.0
#tool nuget:?package=Fluent.Unions.FluentValidation&version=1.1.0
![]()
Fluent.Unions.FluentValidation
Runs a FluentValidation validator and returns the outcome as a Result<T>, so an existing validator plugs into a result pipeline. It builds on Fluent.Unions.
Installation
dotnet add package Fluent.Unions.FluentValidation
Usage
Validate an instance. Every failure ends up in one ValidationErrors with one ValidationError per failure, named after its property. A validator that throws gives the exception as the error.
using FluentValidation;
using Fluent.Unions.FluentValidation;
var validator = new PlaceOrderValidator();
Result<PlaceOrder> command = validator.ValidateToResult(new PlaceOrder(Guid.Empty, 0));
// error: ValidationErrors with two ValidationError (CustomerId, Quantity)
Validate a result inside a pipeline. An error is passed on and the validator is not called.
Result<PlaceOrder> parsed = ParseCommand(request);
Result<PlaceOrder> checkedCommand = await parsed.ValidateAsync(validator, cancellationToken);
With your own result type
Validate(validator) works on your own result type without type arguments. ValidateToResult returns the default Fluent.Unions.Result<T>, so start with Result.From(value).Validate(validator) instead. Without map, a failure goes through FromException. With map, an error type that is data gets every failure. See your own result type.
Result<PlaceOrder> validated = Result.From(new PlaceOrder(Guid.Empty, 0)).Validate(validator);
Validate an Option<T> property only when it has a value. None is always valid.
this.RuleForSome(p => p.Nickname).NotEmpty().MaximumLength(20);
An endpoint that returns the error through Fluent.Unions.AspNetCore answers 400 with every message in errors.
Failures with Severity.Warning or Severity.Info also make the result an error.
Documentation
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Fluent.Unions (>= 1.1.0)
- FluentValidation (>= 12.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.