Nullean.Entities.FluentValidation
0.5.0
dotnet add package Nullean.Entities.FluentValidation --version 0.5.0
NuGet\Install-Package Nullean.Entities.FluentValidation -Version 0.5.0
<PackageReference Include="Nullean.Entities.FluentValidation" Version="0.5.0" />
<PackageVersion Include="Nullean.Entities.FluentValidation" Version="0.5.0" />
<PackageReference Include="Nullean.Entities.FluentValidation" />
paket add Nullean.Entities.FluentValidation --version 0.5.0
#r "nuget: Nullean.Entities.FluentValidation, 0.5.0"
#:package Nullean.Entities.FluentValidation@0.5.0
#addin nuget:?package=Nullean.Entities.FluentValidation&version=0.5.0
#tool nuget:?package=Nullean.Entities.FluentValidation&version=0.5.0
Nullean.Entities.FluentValidation

Keep your FluentValidation pipeline: your constraints run inside it as validators, and your validators run as constraints that generated data can attack.
Without this package, a team with FluentValidation validators and Nullean.Entities constraints keeps two sets of rules apart: the HTTP or mediator pipeline only sees the validators, and the
property tests only see the constraints. This package bridges FluentValidation both ways.
It builds on Nullean.Entities and FluentValidation (Apache-2.0); it does not need the other integration packages. It uses no reflection of its own, but it is not trim or NativeAOT clean, because FluentValidation is not. Built and tested against FluentValidation 12.2.0.
Install
Targets net10.0 and net11.0.
dotnet add package Nullean.Entities
dotnet add package Nullean.Entities.FluentValidation
Quick start
Constraints inside FluentValidation: register the set as a validator, or add it to one you have.
using FluentValidation;
using Nullean.Entities;
using Nullean.Entities.FluentValidation;
services.AddSingleton<IValidator<Customer>>(CustomerRules.All.ToValidator());
public sealed class SignUpValidator : AbstractValidator<Customer>
{
public SignUpValidator()
{
RuleFor(c => c.Name).NotEmpty();
Include(CustomerRules.All.ToValidator());
RuleFor(c => c.Address).SatisfiesConstraints(AddressRules.All); // failures keyed "Address.City"
RuleForEach(c => c.Lines).SatisfiesConstraints(LineRules.All); // "Lines[1].Quantity"
}
}
FluentValidation inside constraints: turn an existing validator into a constraint, and attack it in a test (with Nullean.Entities.CsCheck).
var rules = new CustomerValidator().ToConstraintSet(); // or Constraints<Customer>.FromValidator(validator, "customer-validator")
rules.Probe(samples: 500); // held N, violated M: the validator both passes and fails on generated data
GenAuto.Of<Customer>().ShouldSatisfy(rules); // throws with the smallest generated value it rejects and a seed to replay
What you get
ConstraintSet<T>.ToValidator()andConstraintValidator<T>: anAbstractValidator<T>over a set, for DI,Include,SetValidator, or as a base class.RuleFor(...).SatisfiesConstraints(set)andRuleForEach(...).SatisfiesConstraints(set): a property or each item checked against its own set.- Each violation as a
ValidationFailure:PropertyNameisViolation.Memberunder the rule's property path (no member: the path, or the rule id at the root),ErrorCodethe rule id,SeverityError/Warning/Info from Error/Warning/Hint,AttemptedValuetheEvidence,CustomStatetheViolation.ConstraintValidation.ToFailureis the mapping on its own. Constraints<T>.FromValidator(validator, name),validator.ToConstraint(name)andvalidator.ToConstraintSet(name): a validator as a point-in-time constraint, each failure aViolationwithMemberfromPropertyNameandEvidencefromAttemptedValue(ValidatorConstraints.ToViolation).
Pitfalls and limits
Severityexists in bothFluentValidationandNullean.Entities: alias one (using FvSeverity = FluentValidation.Severity;).- Only point-in-time rules run inside FluentValidation; a validator sees one value, not a change. A null property is skipped; add
NotNull()when null is wrong. FromValidatorruns the validator synchronously, as every constraint is checked: a validator withMustAsync/CustomAsyncrules throwsAsyncValidatorInvokedSynchronouslyException.- One validator is one constraint:
Probecounts the validator, not eachRuleFor. FluentValidation'sErrorCodeis not kept on the way in. - Not trim or NativeAOT clean (FluentValidation compiles expressions). Other FluentValidation versions than 12.2.0 are untested.
Learn more
- This integration on the docs site: https://entities.nullean.net/integration/fluentvalidation/, and every integration: https://entities.nullean.net/integration/
- Getting started with constraints: https://entities.nullean.net/getting-started/
- FluentValidation: https://fluentvalidation.net/
- Property tests over constraints: https://www.nuget.org/packages/Nullean.Entities.CsCheck
- Tests for the package: https://github.com/nullean/entities/tree/main/tests/Nullean.Entities.FluentValidation.Tests
- Source and issues: https://github.com/nullean/entities
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
- FluentValidation (>= 12.2.0)
- Nullean.Entities (>= 0.5.0)
-
net11.0
- FluentValidation (>= 12.2.0)
- Nullean.Entities (>= 0.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.