Koto.Application
0.5.0-preview.5
See the version list below for details.
dotnet add package Koto.Application --version 0.5.0-preview.5
NuGet\Install-Package Koto.Application -Version 0.5.0-preview.5
<PackageReference Include="Koto.Application" Version="0.5.0-preview.5" />
<PackageVersion Include="Koto.Application" Version="0.5.0-preview.5" />
<PackageReference Include="Koto.Application" />
paket add Koto.Application --version 0.5.0-preview.5
#r "nuget: Koto.Application, 0.5.0-preview.5"
#:package Koto.Application@0.5.0-preview.5
#addin nuget:?package=Koto.Application&version=0.5.0-preview.5&prerelease
#tool nuget:?package=Koto.Application&version=0.5.0-preview.5&prerelease
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: Task<AppResult> for a command without a value, Task<AppResult<TResult>> otherwise |
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 / AppResult<T> |
What a handler returns: success (with a value) or an ErrorList<EnrichedError>. Domain errors and results convert implicitly |
EnrichedError |
A domain Error plus request context: Field and optional Details; keeps the original as Inner |
ErrorEnrichment |
What a handler can add to an error: ForField, Enrich<TError>, 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
Wiring mistakes stop the application at start, not at the first request:
- a command or query in the scanned assemblies has no handler, or more than one;
- a command or query declares a result wrapper as its result —
ICommand<Result<OrderId>>instead ofICommand<OrderId>; AddTransactionBehavior()is enabled and noIUnitOfWorkis registered.
Set o.ValidateHandlers = false if handlers are registered by hand.
From the domain to the client
| Layer | Returns | Errors |
|---|---|---|
| Domain | Result / Result<T> |
Error records from the catalog |
| Application (handlers) | AppResult / AppResult<T> |
EnrichedError |
| API | Envelope<T> |
EnvelopeError (flat: code, message, field, details) |
A domain outcome is the handler's answer as it is. An Error, x.Errors or a whole Result converts
implicitly into AppResult, and every error is kept:
public sealed record CancelOrderCommand(Guid OrderId, string Reason) : ICommand;
public sealed class CancelOrderHandler(IOrderRepository orders, TimeProvider clock)
: ICommandHandler<CancelOrderCommand>
{
public async Task<AppResult> HandleAsync(CancelOrderCommand command, CancellationToken ct = default)
{
var order = await orders.GetByIdAsync(new OrderId(command.OrderId), ct);
if (order is null) return new OrderNotFound(command.OrderId);
return order.Cancel(command.Reason, clock.GetUtcNow());
}
}
A command that returns a value declares it — ICommand<Guid> — and its handler returns
Task<AppResult<Guid>>. The value converts implicitly too: return order.Id.Value;.
When the handler knows more than the domain
Three verbs add to an error on its way out. Use them only when there is something to add.
// which request field was wrong — the client highlights the input
if (await customers.IsRegisteredAsync(email, ct))
return new EmailAlreadyRegistered(email.Address).ForField(nameof(command.Email));
// every error of a failed result, bound to one field
var lines = Result.Traverse(command.Lines, line => OrderLine.Create(line.Product, line.Quantity));
if (lines.IsFailure) return lines.Errors.ForField(nameof(command.Lines));
// a fuller error with data only the application has
var joined = meetup.Join(user.Id);
if (joined.IsFailure)
return joined.Errors.Enrich<MeetupFull>(full => new MeetupFullWithAlternative(full, alternative.Id));
A fuller error is a record deriving from EnrichedError that wraps the domain error and adds its own
properties:
public sealed record MeetupFullWithAlternative(MeetupFull Cause, Guid AlternativeMeetupId)
: EnrichedError(Cause);
On the wire the chain is flat: details = { "capacity": 8, "alternativeMeetupId": "…" }. A
StronglyTypedId in an error (OrderAlreadyCancelled(OrderId OrderId)) is sent as its value:
"orderId": "7c9e…". WithDetails(...) is for optional extras; the record properties are the contract.
Errors found by a validator are bound to their field by the library (see Koto.Validation).
Do not return x.FirstError — it is one error of several, and the compiler rejects it (KOTO002). Return x.Errors.
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<Guid>>.
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 / AppResult<T> (no Unit), domain errors and results convert into them implicitly, 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 | 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
- Koto.Domain (>= 0.5.0-preview.5)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.7)
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 |
0.5.0-preview.5 — bug fix: ListMustContainNumberOfItems threw on a missing list (HTTP 500); new rule MustBePresent() reports a missing value that is not a value object as general.value.is-required, bound to the field. Since preview.4: a value object's factory only parses, MustBeValueObjectOrNull for optional values; analyzers KOTO001/KOTO002. Migration guide: https://github.com/arigatory/Koto/blob/main/docs/migrations/0.4-to-0.5.md