Koto.Domain 0.3.0-preview.3

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

Koto.Domain

DDD building blocks for .NET microservices. Zero external dependencies.

Install

dotnet add package Koto.Domain

What's included

Type Purpose
AggregateRoot<TId> Base class that collects domain events
Entity<TId> Identity-based equality (transient entities are never equal)
ValueObject Component-based equality
StronglyTypedId<T> Typed wrappers for Guid / int / string IDs
Result<T> Explicit success/failure without exceptions; carries one or many errors (Errors)
Result (static) Success() / Failure(…) for void flows, Combine(…) to aggregate several results
IResultFactory<TSelf> Static-abstract failure factory for generic infrastructure (no reflection)
Error Structured error: Code + Message + optional Field
Errors.General Shared factory errors (not-found, required, …)
IDomainEvent / DomainEvent Event interfaces and base record (init properties survive JSON round-trips)
Unit Return type for commands that produce no value

IRepository<TAgg, TId> lives in Koto.Application (next to IUnitOfWork) — the port belongs to the layer that consumes it (handlers); the domain stays persistence-free.

Usage

Value Object

public sealed class Email : ValueObject
{
    public string Value { get; }
    private Email(string value) => Value = value;

    public static Result<Email> Create(string value) =>
        string.IsNullOrWhiteSpace(value) ? Errors.General.ValueIsRequired() :
        value.Length > 150              ? Errors.General.InvalidLength(1, 150) :
                                          new Email(value);

    protected override IEnumerable<object?> GetEqualityComponents()
    {
        yield return Value.ToLowerInvariant();
    }
}

Aggregate Root

public sealed record OrderId(Guid Value) : StronglyTypedId<Guid>(Value);

public class Order : AggregateRoot<OrderId>
{
    public static Result<Order> Place(IReadOnlyList<OrderItem> items)
    {
        if (items.Count == 0)
            return Errors.General.CollectionIsTooSmall(1, 0);

        var order = new Order(new OrderId(Guid.NewGuid()));
        order.AddDomainEvent(new OrderPlacedEvent(order.Id));
        return order;
    }

    public Result<Unit> Cancel(string reason)
    {
        if (Status == OrderStatus.Cancelled)
            return new Error("orders.already-cancelled", "Order is already cancelled.");

        Status = OrderStatus.Cancelled;
        AddDomainEvent(new OrderCancelledEvent(Id, reason));
        return Unit.Value;
    }
}

Result chaining

Result<OrderId> result = await ValidateAsync(request)
    .BindAsync(dto => Order.Place(dto.Items))
    .TapAsync(order => repository.Add(order))
    .MapAsync(order => order.Id);

Multiple errors and Combine

// Aggregate several factory results — ALL errors are collected, not just the first:
var combined = Result.Combine(Email.Create(dto.Email), Name.Create(dto.Name));
if (combined.IsFailure)
    return Result<User>.Failure(combined.Errors);   // every error, each with its own Code

var (email, name) = combined.Value;

Async match

// Async success handler + sync failure handler — no Task.FromResult noise:
return await result.MatchAsync(
    onSuccess: async order => await BuildResponseAsync(order, ct),
    onFailure: error => ErrorResponse(error));

License

MIT

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.
  • net10.0

    • No dependencies.

NuGet packages (7)

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

Package Downloads
Koto.Application

CQRS dispatcher, pipeline behaviors, and cross-service integration abstractions for .NET microservices. Depends only on Koto.Domain and Microsoft.Extensions abstractions.

Koto.Validation

FluentValidation extensions for Koto: MustBeValueObject, MustBeEntity, ListMustContainNumberOfItems, and ValidationBehavior pipeline integration.

Koto.EventSourcing.Marten

Event Sourcing on PostgreSQL via Marten 8: EventSourcedAggregateRoot, event-sourced repository, inline and async projections.

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.Infrastructure.EFCore

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

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.0-preview.3 67 7/11/2026
0.3.0-preview.2 65 7/11/2026
0.3.0-preview.1 87 7/3/2026
0.2.0-preview.1 89 6/28/2026
0.1.0-preview.5 94 5/13/2026
0.1.0-preview.4 85 5/13/2026
0.1.0-preview.3 82 5/13/2026
0.1.0-preview.2 68 5/11/2026
0.1.0-preview.1 65 5/11/2026