Koto.Validation
0.5.0-preview.4
See the version list below for details.
dotnet add package Koto.Validation --version 0.5.0-preview.4
NuGet\Install-Package Koto.Validation -Version 0.5.0-preview.4
<PackageReference Include="Koto.Validation" Version="0.5.0-preview.4" />
<PackageVersion Include="Koto.Validation" Version="0.5.0-preview.4" />
<PackageReference Include="Koto.Validation" />
paket add Koto.Validation --version 0.5.0-preview.4
#r "nuget: Koto.Validation, 0.5.0-preview.4"
#:package Koto.Validation@0.5.0-preview.4
#addin nuget:?package=Koto.Validation&version=0.5.0-preview.4&prerelease
#tool nuget:?package=Koto.Validation&version=0.5.0-preview.4&prerelease
Koto.Validation
FluentValidation extensions and the validation pipeline behavior for the Koto suite.
Uses FluentValidation v12 (Apache 2.0 on all versions), pinned to
[12.0.0,13.0.0).
Install
dotnet add package Koto.Validation
What's included
| Type | Purpose |
|---|---|
KotoValidators.MustBeValueObject<T, TSource, TValueObject> |
Validates a property by calling a domain factory (Func<TSource, Result<TVO>>) — any source type |
KotoValidators.MustBeValueObjectOrNull<T, TSource, TValueObject> |
The same for a value that may be absent: null is fine, a value that is there must pass the factory |
KotoValidators.ListMustContainNumberOfItems |
Min/max count rule with Errors.General.CollectionIsTooSmall/Large |
ValidationBehavior<TRequest, TResponse> |
Runs all validators for the request sequentially before the handler |
ValidationRuleFailed |
The error for rules not backed by a domain factory (validation.rule.failed, details.rule = the rule's code) |
AddValidationBehavior() |
Puts the behavior at an explicit position in KotoApplicationOptions |
AddKotoValidation(assemblies) |
Scans IValidator<T> implementations (registers the behavior if it was not added through the options) |
Register
builder.Services.AddKotoApplication(
o => o.AddLoggingBehavior().AddValidationBehavior().AddTransactionBehavior(), // Logging → Validation → Transaction
typeof(PlaceOrderHandler).Assembly);
builder.Services.AddKotoValidation(typeof(PlaceOrderValidator).Assembly);
With this order a validation failure never opens a transaction. Calling AddKotoValidation alone
still works — the behavior is then appended after the behaviors configured in the options.
Write a validator — one source of truth
The validation logic lives in the domain factory; the validator only calls it:
public sealed class PlaceOrderValidator : AbstractValidator<PlaceOrderCommand>
{
public PlaceOrderValidator()
{
RuleFor(x => x.Email).MustBeValueObject(Email.Create); // string source
RuleFor(x => x.Quantity).MustBeValueObject(Quantity.Create); // int source — any type works
RuleFor(x => x.Items).ListMustContainNumberOfItems(1, 100);
RuleFor(x => x.CustomerId).NotEmpty(); // plain FluentValidation rule
}
}
Validators are keyed by the concrete command type and discovered by the pipeline automatically.
What the handler never sees, and what the client gets
On failure the behavior returns an AppResult carrying one EnrichedError per failure, each
bound to its field:
- a
MustBeValueObjectfailure keeps the domain error —identity.email.invalid, … — with its record properties asdetails; - a required field that the request left out is
general.value.is-required: the factory is not asked about a value that is not there (see below); - any other rule (
NotEmpty(),Length(),MustAsync()) becomesvalidation.rule.failedwithdetails.ruleset to the rule's error code (NotEmptyValidatoror yourWithErrorCodevalue).
Nothing is collapsed into a string; the API layer renders every error inside the response envelope.
Validators run one after another, so async rules may share scoped services such as a DbContext.
A factory parses, the request requires
Email.Create answers one question: is this string an email? That an email is needed at all is a rule of
the request, not of Email, so a factory takes a non-nullable value and has no "required" error. The
validator says both things in the open — what must be there, and what may be absent:
public sealed record RegisterCustomerCommand(string Email, string? Phone, int? Age) : ICommand<Guid>;
RuleFor(x => x.Email).MustBeValueObject(Email.Create); // must be there, and be an email
RuleFor(x => x.Phone).MustBeValueObjectOrNull(Phone.Create); // may be absent; when it is there it must be a phone
RuleFor(x => x.Age).MustBeValueObjectOrNull(Age.Create); // the same for a number
| The request sent | MustBeValueObject |
MustBeValueObjectOrNull |
|---|---|---|
nothing (null) |
general.value.is-required |
fine |
"" or anything the factory refuses |
the factory's error | the factory's error |
| a valid value | fine | fine |
A nullable type alone does not make a value optional: a missing Phone under MustBeValueObject is
general.value.is-required. Nothing about optionality is hidden — not in the domain, not in the library:
the name of the rule says it.
In the handler an optional value is parsed only when it is there:
var phone = command.Phone is null ? null : Phone.Create(command.Phone);
if (phone is { IsFailure: true }) return phone.Errors.ForField(nameof(command.Phone));
var customer = Customer.Register(email.Value, phone?.Value); // Register(Email email, Phone? phone)
Upgrading from 0.4
0.5 adds AddValidationBehavior() to position the behavior explicitly, removes MustBeEntity, NotEmptyWithKotoError and LengthWithKotoError, runs validators sequentially, and reports plain rules as validation.rule.failed (details.rule) instead of the FluentValidation error code. The step-by-step guide for the whole suite, with before/after code, is
docs/migrations/0.4-to-0.5.md.
| 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. |
-
net10.0
- FluentValidation (>= 12.0.0 && < 13.0.0)
- Koto.Application (>= 0.5.0-preview.4)
- Koto.Domain (>= 0.5.0-preview.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Koto.Validation:
| Package | Downloads |
|---|---|
|
Koto.Api.FastEndpoints
FastEndpoints integration for Koto: CQRS base endpoints responding with the Koto Envelope, binding errors in the same envelope, correlation ID middleware, and global exception handler. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.5.0-preview.9 | 50 | 11/30/2026 |
| 0.5.0-preview.8 | 60 | 11/30/2026 |
| 0.5.0-preview.7 | 57 | 11/29/2026 |
| 0.5.0-preview.6 | 49 | 11/29/2026 |
| 0.5.0-preview.5 | 56 | 11/29/2026 |
| 0.5.0-preview.4 | 56 | 11/29/2026 |
| 0.5.0-preview.3 | 51 | 11/29/2026 |
| 0.5.0-preview.2 | 59 | 11/29/2026 |
| 0.5.0-preview.1 | 64 | 11/8/2026 |
| 0.4.0 | 177 | 7/21/2026 |
| 0.3.0-preview.15 | 83 | 7/21/2026 |
| 0.3.0-preview.14 | 85 | 7/21/2026 |
| 0.3.0-preview.13 | 83 | 7/21/2026 |
| 0.3.0-preview.12 | 75 | 7/21/2026 |
| 0.3.0-preview.11 | 76 | 7/21/2026 |
| 0.3.0-preview.10 | 77 | 7/21/2026 |
| 0.3.0-preview.9 | 88 | 7/21/2026 |
| 0.3.0-preview.8 | 79 | 7/21/2026 |
| 0.3.0-preview.7 | 89 | 7/21/2026 |
| 0.3.0-preview.6 | 85 | 7/20/2026 |
0.5.0-preview.4 — a value object's factory parses and never answers "required": MustBeValueObject reports a missing value itself (general.value.is-required, bound to the field) and does not call the factory with null. Remove "required" errors from value-object factories. Since preview.3: analyzers KOTO001 (a result is discarded) and KOTO002 (FirstError returned as the failure) are errors. Migration guide: https://github.com/arigatory/Koto/blob/main/docs/migrations/0.4-to-0.5.md