Koto.Application 0.5.0-preview.1

This is a prerelease version of Koto.Application.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Koto.Application --version 0.5.0-preview.1
                    
NuGet\Install-Package Koto.Application -Version 0.5.0-preview.1
                    
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.Application" Version="0.5.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Koto.Application" Version="0.5.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="Koto.Application" />
                    
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.Application --version 0.5.0-preview.1
                    
#r "nuget: Koto.Application, 0.5.0-preview.1"
                    
#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.Application@0.5.0-preview.1
                    
#: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.Application&version=0.5.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Koto.Application&version=0.5.0-preview.1&prerelease
                    
Install as a Cake Tool

Koto.Application

CQRS dispatcher, pipeline behaviors, the application-layer error model (EnrichedError, AppResult<T>, Envelope<T>) and cross-service integration abstractions. Part of the Koto suite.

Install

dotnet add package Koto.Application

What's included

Type Purpose
ICommand / ICommand<TResult> / IQuery<TResult> Marker interfaces for write and read operations
ICommandHandler<T> / ICommandHandler<T, TResult> / IQueryHandler<TQuery, TResult> Handler contracts — all return Task<AppResult<…>>
ICqrsDispatcher Dispatches commands and queries through the pipeline
IPipelineBehavior<TRequest, TResponse> Middleware for the CQRS pipeline
KotoApplicationOptions Opt-in behaviors (AddLoggingBehavior(), AddTransactionBehavior(), AddBehavior(type)), ValidateHandlers
LoggingBehavior<,> / TransactionBehavior<,> Built-in behaviors
IUnitOfWork / IRepository<TAgg, TId> Persistence ports implemented by infrastructure
AppResult<T> The result type of handlers: a value or an ErrorList<EnrichedError>
EnrichedError A domain Error plus request context: Field and optional Details; keeps the original as Inner
ErrorEnrichment The explicit verbs ForField, Enrich(), Enrich(map), WithDetails
ErrorDetails Flattens an error's record properties into wire details
Envelope<T> / EnvelopeError The one response shape for every transport
IIntegrationEvent / IntegrationEvent / IIntegrationCommand Cross-service contracts
IIntegrationEventPublisher / IIntegrationCommandDispatcher Implemented by Koto.Messaging.Wolverine
IntegrationEventTopics Topic constant convention for integration contracts
PagedList<T> Page of results with metadata
KotoApplicationAssemblies The scanned assemblies (used by the API layer's error-catalog checks)

Register

builder.Services.AddKotoApplication(
    o => o.AddLoggingBehavior().AddValidationBehavior().AddTransactionBehavior(),  // order = execution order
    typeof(PlaceOrderHandler).Assembly);
builder.Services.AddKotoValidation(typeof(PlaceOrderHandler).Assembly);           // scans validators

AddKotoApplication fails at startup when a command or query in the scanned assemblies has no handler, or more than one — a missing handler is found before the first request, not by it. Set o.ValidateHandlers = false if handlers are registered by hand.

Three layers, two result types

Layer Returns Errors
Domain Result<T> Error records from the catalog
Application (handlers) AppResult<T> EnrichedError
API Envelope<T> EnvelopeError (flat: code, message, field, details)

There is no implicit conversion from Result<T> to AppResult<T>. Leaving a handler, a failure goes through one of three explicit verbs, and each says what was added:

public sealed class VerifyOtpHandler(IOtpRepository otps, IMeetupRepository meetups, IUnitOfWork uow)
    : ICommandHandler<VerifyOtpCommand, TokenPairDto>
{
    public async Task<AppResult<TokenPairDto>> HandleAsync(VerifyOtpCommand command, CancellationToken ct = default)
    {
        var email = Email.Create(command.Email);
        if (email.IsFailure) return email.Errors.ForField(nameof(command.Email));   // 1. bound to a request field

        var challenge = await otps.GetLatestAsync(email.Value, ct);
        if (challenge is null) return new OtpInvalidCode(attemptsLeft: 0).Enrich();   // application-level error

        var verified = challenge.Verify(command.Code, DateTimeOffset.UtcNow);
        if (verified.IsFailure) return verified.Errors.Enrich();                      // 2. nothing to add — said explicitly

        var joined = meetup.Join(user.Id);
        if (joined.IsFailure)
            return joined.Errors.Enrich(e => e is MeetupFull full                      // 3. fuller typed error with data from the DB
                ? new MeetupFullWithAlternative(full, alternative.Id)
                : e.Enrich());

        await uow.CommitAsync(ct);
        return new TokenPairDto(...);                                                   // success: implicit
    }
}

Typed enrichment is a record deriving from EnrichedError that wraps the domain error and adds guaranteed properties:

public sealed record MeetupFullWithAlternative(MeetupFull Cause, Guid AlternativeMeetupId)
    : EnrichedError(Cause);

On the wire the chain is flattened: details = { "capacity": 8, "alternativeMeetupId": "…" }. EnrichedError.Details (dictionary, via WithDetails) is for optional additions only — the record properties are the contract.

Several domain results can be bound to fields first and combined later:

var fields = Result.Combine(
    Email.Create(cmd.Email).ForField("email"),
    Phone.Create(cmd.Phone).ForField("phone"));
if (fields.IsFailure) return fields.Errors.Enrich();

Envelope — one shape for every transport

{ "success": true,  "result": { "id": "…" }, "errors": [], "correlationId": "0f3c…", "timestamp": "2026-11-08T02:11:03Z" }

{ "success": false, "result": null,
  "errors": [ { "code": "identity.otp.too-many-attempts", "message": "Too many attempts.",
                "field": null, "details": { "retryAfterSeconds": 42 } } ],
  "correlationId": "0f3c…", "timestamp": "2026-11-08T02:11:09Z" }

Envelope<T> lives here, not in the HTTP package, so a SignalR hub or a Kafka reply can return it too:

public async Task<Envelope<ChatReplyDto>> Ask(AskCommand command)          // SignalR hub method
{
    var result = await dispatcher.SendAsync<ChatReplyDto>(command, Context.ConnectionAborted);
    return result.ToEnvelope(timeProvider.GetUtcNow());
}

On HTTP every failure is sent as Envelope<object?>, so result is null whatever the result type; ToEnvelope<T> on a typed transport (a hub method returning Envelope<Guid>) yields default(T) on failure, so prefer reference DTOs there. field is camelCased per path segment to match the JSON the client sent; success is the discriminator clients branch on. HTTP status codes remain meaningful and are chosen by the API layer (Koto.Api.AspNetCore).

Pipeline behaviors

Behaviors are resolved against the concrete command/query type: an open-generic registration like ValidationBehavior<,> closes over PlaceOrderCommand at dispatch time, so IValidator<PlaceOrderCommand> is discovered. A behavior can also target a single request by implementing IPipelineBehavior<PlaceOrderCommand, AppResult<OrderId>>.

TransactionBehavior commits on success and rolls back on a failed AppResult; commands marked INonTransactionalCommand manage IUnitOfWork themselves.

Pagination

PagedList<T> carries Items, Page, PageSize, TotalCount, TotalPages, HasNextPage, HasPreviousPage. Return it from query handlers (IQuery<PagedList<OrderDto>>); materialize from EF Core with ToPagedListAsync in Koto.Infrastructure.EFCore.

Upgrading from 0.4

0.5 changes the handler contract: handlers and ICqrsDispatcher return AppResult<T>, a domain Result<T> leaves a handler through ForField / Enrich() / Enrich(map), Error.Field moved to EnrichedError, and AddKotoApplication fails at startup when a command has no handler. 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 (9)

Showing the top 5 NuGet packages that depend on Koto.Application:

Package Downloads
Koto.Infrastructure.Http

Anti-Corruption Layer for HTTP calls between services: typed ServiceHttpClient base, Result-mapped error handling, correlation ID propagation, and standard resilience.

Koto.Validation

FluentValidation extensions for Koto: MustBeValueObject, ListMustContainNumberOfItems, the ValidationBehavior pipeline behavior (enriched errors per field) and AddValidationBehavior ordering.

Koto.EventSourcing.Marten

Event Sourcing on PostgreSQL via Marten: event-sourced repository, MartenUnitOfWork, inline and async projections. The aggregate base (EventSourcedAggregateRoot) lives in Koto.Domain, so domain projects never reference this package.

Koto.Messaging.Wolverine

Wolverine-based implementation of Koto messaging abstractions: integration event publishing, command dispatching, Kafka consumers with idempotency, correlation propagation, and DLQ routing.

Koto.Infrastructure.EFCore

EF Core 10 integration for Koto DDD: generic repository, strongly-typed ID converters, pagination, and Wolverine outbox wiring.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.0-preview.9 75 11/30/2026
0.5.0-preview.8 80 11/30/2026
0.5.0-preview.7 81 11/29/2026
0.5.0-preview.6 75 11/29/2026
0.5.0-preview.5 79 11/29/2026
0.5.0-preview.4 79 11/29/2026
0.5.0-preview.3 76 11/29/2026
0.5.0-preview.2 77 11/29/2026
0.5.0-preview.1 117 11/8/2026
0.4.0 276 7/21/2026
0.3.0-preview.15 124 7/21/2026
0.3.0-preview.14 111 7/21/2026
0.3.0-preview.13 106 7/21/2026
0.3.0-preview.12 109 7/21/2026
0.3.0-preview.11 108 7/21/2026
0.3.0-preview.10 113 7/21/2026
0.3.0-preview.9 115 7/21/2026
0.3.0-preview.8 105 7/21/2026
0.3.0-preview.7 104 7/21/2026
0.3.0-preview.6 100 7/20/2026
Loading failed

0.5.0-preview.1 — new error model: abstract Error catalog, AppResult for handlers, one Envelope response for every transport (ADR-026). Breaking for 0.4 consumers; migration guide: https://github.com/arigatory/Koto/blob/main/docs/migrations/0.4-to-0.5.md