Koto.Infrastructure.EFCore 0.5.0-preview.2

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

Koto.Infrastructure.EFCore

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

Install

dotnet add package Koto.Infrastructure.EFCore
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL  # or your preferred provider

What's included

Type Purpose
KotoDbContext Abstract DbContext; auto-applies StronglyTypedIdConvention; clears domain events after save
Repository<TAgg, TId> Generic IRepository implementation backed by EF Core
StronglyTypedIdValueConverter<TId, TRaw> EF Core ValueConverter for StronglyTypedId<T> properties
StronglyTypedIdConvention Auto-applies converters to all strongly-typed ID properties
AddKotoEFCore<TContext>() Registers the DbContext via Wolverine's EF Core integration

Usage

1 — Define your DbContext

public class AppDbContext : KotoDbContext
{
    public AppDbContext(DbContextOptions options) : base(options) { }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly);
    }
}

StronglyTypedIdConvention is applied automatically — no manual HasConversion calls needed.

2 — Register

// Program.cs
builder.Services.AddKotoEFCore<AppDbContext>(opts =>
    opts.UseNpgsql(builder.Configuration.GetConnectionString("Db")));

// Wolverine setup — durable outbox (required for events to be delivered)
builder.Host.UseWolverine(opts =>
{
    // Handlers outside the entry assembly have to be added to discovery explicitly:
    opts.Discovery.IncludeAssembly(typeof(SomeHandler).Assembly);

    // Durable outbox: the envelopes are stored in the service's Postgres
    opts.PersistMessagesWithPostgresql(connectionString);   // WolverineFx.Postgresql
    opts.Policies.UseDurableOutboxOnAllSendingEndpoints();

    opts.UseEntityFrameworkCoreTransactions();

    // For saves INSIDE Wolverine handlers (consumers):
    opts.PublishDomainEventsFromEntityFrameworkCore<IHasDomainEvents, IDomainEvent>(
        e => e.DomainEvents);
});

Domain events from plain code (HTTP endpoints)

PublishDomainEventsFromEntityFrameworkCore is a codegen policy that only runs inside Wolverine handlers. For saves from ordinary code (FastEndpoints → ICommandHandler), AddKotoEFCore registers EfCoreUnitOfWork<TContext> as the default IUnitOfWork (TryAddScoped — your own registration wins): on CommitAsync it collects uncommitted domain events from tracked aggregates and publishes them through Wolverine's EF Core outbox in the same transaction as your entity changes:

public async Task<AppResult<Guid>> HandleAsync(PlaceOrderCommand command, CancellationToken ct = default)
{
    var placed = Order.Place(...);         // AddDomainEvent(...) inside
    if (placed.IsFailure) return placed.Errors;

    _orders.Add(placed.Value);
    await _unitOfWork.CommitAsync(ct);     // entities + outbox messages in one transaction
    return placed.Value.Id.Value;
}

If aggregates raised domain events and no Wolverine outbox (IDbContextOutbox) is registered, CommitAsync throws instead of saving and dropping the events silently — configure Wolverine or register your own IUnitOfWork that dispatches them.

3 — Use a repository

public class OrderRepository : Repository<Order, OrderId>
{
    public OrderRepository(AppDbContext ctx) : base(ctx) { }
}

Or rely on the registered IRepository<Order, OrderId> directly.

Pagination

var page = await context.Orders
    .Where(o => o.CustomerId == customerId)
    .OrderByDescending(o => o.CreatedAt)
    .ToPagedListAsync(page: 1, pageSize: 20, ct);

The query must be ordered (OrderBy), otherwise page boundaries are undefined.

Upgrading from 0.4

0.5 makes EfCoreUnitOfWork.CommitAsync throw when aggregates raised domain events and no Wolverine outbox is registered (0.4 dropped them silently), and removes ISpecification<T> / Specification<T> / SpecificationEvaluator. 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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.0-preview.9 45 11/30/2026
0.5.0-preview.8 55 11/30/2026
0.5.0-preview.7 55 11/29/2026
0.5.0-preview.6 50 11/29/2026
0.5.0-preview.5 59 11/29/2026
0.5.0-preview.4 53 11/29/2026
0.5.0-preview.3 54 11/29/2026
0.5.0-preview.2 55 11/29/2026
0.5.0-preview.1 58 11/8/2026
0.4.0 167 7/21/2026
0.3.0-preview.15 87 7/21/2026
0.3.0-preview.14 81 7/21/2026
0.3.0-preview.13 80 7/21/2026
0.3.0-preview.12 79 7/21/2026
0.3.0-preview.11 84 7/21/2026
0.3.0-preview.10 86 7/21/2026
0.3.0-preview.9 85 7/21/2026
0.3.0-preview.8 75 7/21/2026
0.3.0-preview.7 80 7/21/2026
0.3.0-preview.6 83 7/20/2026
Loading failed

0.5.0-preview.2 — a shorter happy path (ADR-027): Result / AppResult without Unit, domain errors and results convert into AppResult implicitly, EventSourcedAggregateRoot lives in Koto.Domain; Koto.Testing gets typed error assertions, event assertions on the aggregate, Layers checks and DomainMap. Nothing old is kept as a synonym: Unit, Result.Success(), AppResult.Success() and the no-argument Enrich() are removed, Enrich(map) became Enrich<TError>(fuller). Breaking for 0.4 and 0.5.0-preview.1 consumers; migration guide: https://github.com/arigatory/Koto/blob/main/docs/migrations/0.4-to-0.5.md