Koto.Validation 0.5.0-preview.3

This is a prerelease version of Koto.Validation.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Koto.Validation --version 0.5.0-preview.3
                    
NuGet\Install-Package Koto.Validation -Version 0.5.0-preview.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Koto.Validation" Version="0.5.0-preview.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Koto.Validation" Version="0.5.0-preview.3" />
                    
Directory.Packages.props
<PackageReference Include="Koto.Validation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Koto.Validation --version 0.5.0-preview.3
                    
#r "nuget: Koto.Validation, 0.5.0-preview.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Koto.Validation@0.5.0-preview.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Koto.Validation&version=0.5.0-preview.3&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Koto.Validation&version=0.5.0-preview.3&prerelease
                    
Install as a Cake Tool

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.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 MustBeValueObject failure keeps the domain error — general.value.is-required, identity.email.invalid, … — with its record properties as details;
  • any other rule (NotEmpty(), Length(), MustAsync()) becomes validation.rule.failed with details.rule set to the rule's error code (NotEmptyValidator or your WithErrorCode value).

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.

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed

0.5.0-preview.3 — the compiler keeps a refusal from getting lost (ADR-028): two analyzers ship inside Koto.Domain and reach every project that references a Koto package. KOTO001: a result is discarded (order.Cancel(reason, now); on a line of its own). KOTO002: FirstError is returned as the failure instead of Errors. Both are errors, so existing code may stop building; migration guide: https://github.com/arigatory/Koto/blob/main/docs/migrations/0.4-to-0.5.md