Aaron.Akka.Durable.TestKit 0.1.0-alpha.8

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

Akka.Durable

Akka.Durable is a proof of concept, not an official Akka.NET project. It is published as Aaron.Akka.Durable because the Akka.* NuGet prefix is reserved for official Akka.NET packages. Expect breaking changes between releases.

Akka.Durable gives you event-sourced entities on Akka.NET. Define their behavior with pure Decide and Evolve functions, keep the impure work in effect handlers, then send commands through typed references. The runtime handles persistence, recovery, and routing in local or clustered deployments. Callers can wait for an entity's state, or watch it, without polling.

Inject it. Send a message.

Entity reference factories are .NET DI services. Call AddDurableEntities() at startup, then inject IEntityRefs<InvoiceCommand> into any controller, hosted service, or application service:

public sealed class BillingService(IEntityRefs<InvoiceCommand> invoices)
{
    public Task<IssueReply> IssueAsync(EntityId id, CancellationToken ct) =>
        invoices.Get(id).Ask(new IssueInvoice(250m, "billing@example.com"), ct);

    public void Remind(EntityId id) =>
        invoices.Get(id).Tell(new SendReminder());
}

That's the caller API: choose an ID, send a command, get its declared reply type. The first message creates or recovers the entity. The same calls work with local hosting and Cluster Sharding. Register and host the entity once at startup.

Define its behavior

Here is the Invoice behind those calls. Issuing an invoice runs a VerifyRecipient effect, and its answer comes back as a command. This is the state that handles it:

public static InvoiceDecision Decide(InvoiceState state, InvoiceCommand command, InvoiceContext ctx) =>
    state switch
    {
        // ... Draft: IssueInvoice persists VerificationStarted and issues the VerifyRecipient effect.
        Verifying v => command switch
        {
            // The answer to VerifyRecipient arrives as a command.
            // v.Request is the IssueInvoice we are still answering.
            RecipientVerified =>
                ctx.Persist(new InvoiceIssued(v.Request.Total, v.Request.Recipient, ctx.UtcNow))
                    .Schedule("reminder", TimeSpan.FromDays(30), new SendReminder())
                    .Reply(v.Request, new InvoiceAccepted(ctx.EntityId)),
            RecipientRejected r =>
                ctx.Persist(new VerificationFailed(r.Reason))
                    .Reply(v.Request, new InvoiceRejected(r.Reason)),
            _ => NotHere(command, ctx),   // refused or ignored: it does not belong here
        },
        // ... Issued and Paid have the same shape.
    };

Every state looks like this: see the complete invoice.

VerifyRecipient is the effect: a plain record, journaled in the same write as VerificationStarted. The definition puts the invoice together. Its GaveUp is the command Decide gets when the directory gives no answer:

[AkkaSerializable(Manifest = "verify-recipient-v1")]
public sealed record VerifyRecipient([property: AkkaField(0)] string Recipient) : IInvoiceProtocol;

public static readonly EntityDefinition<InvoiceState, InvoiceCommand, InvoiceEvent> Definition =
    new(new EntityTypeName("invoices"), _ => new Draft(), Decide, Evolve,
        GaveUp: g => new RecipientRejected($"directory: {g.Reason}"));

The only impure code is the effect's handler, which Akka.Durable resolves from a fresh DI scope when the effect runs. The handler's second type argument says what kind of answer it produces, here a command that goes back through Decide:

public sealed class VerifyRecipientHandler(IRecipientDirectory directory)
    : IEffectHandler<VerifyRecipient, InvoiceCommand>
{
    public async Task<InvoiceCommand> HandleAsync(
        VerifyRecipient effect,
        EffectDelivery delivery,
        CancellationToken ct) =>
        await directory.LookupAsync(effect.Recipient, ct) switch
        {
            Known => new RecipientVerified(),
            Unknown u => new RecipientRejected(u.Reason),
        };
}

// at startup, next to the other services
services.AddEffectHandler<VerifyRecipient, InvoiceCommand, VerifyRecipientHandler>();

The state, command, event, and reply declarations are in the guide. You write the domain functions and the handlers; Akka.Durable supplies the actor.

The calling surface is small: IEntityRef sends commands, and IDurableEntityRef adds state reads:

public interface IEntityRef<in TCommand>
{
    EntityId Id { get; }

    void Tell(TCommand command, IActorRef? sender = null);

    Task<TReply> Ask<TReply>(
        IReplies<TCommand, TReply> command,
        CancellationToken cancellationToken = default) where TReply : notnull;
}

public interface IDurableEntityRef<in TCommand, TState, TEvent> : IEntityRef<TCommand>
{
    Task<StateSnapshot<TState>> GetStateAsync(CancellationToken cancellationToken = default);

    Task<StateSnapshot<TState>> WaitForStateAsync(
        Func<TState, bool> until,
        CancellationToken cancellationToken);

    IAsyncEnumerable<StateSnapshot<TState>> WatchStateAsync(
        CancellationToken cancellationToken = default);
}

Ask infers its reply type from the command. GetStateAsync returns the committed state and its journal sequence number. Both reference factories can be injected: use IEntityRefs<InvoiceCommand> for messaging, or IDurableEntityRefs<InvoiceCommand, InvoiceState, InvoiceEvent> for messaging plus state reads. Both are registered by AddDurableEntities(). The registry is keyed by command type, so each entity type must have its own command type.

To react to a change, do not read the state in a loop. Wait for the state, or watch it:

// In a request handler: wait at most five seconds for the payment.
using var limit = CancellationTokenSource.CreateLinkedTokenSource(ct);
limit.CancelAfter(TimeSpan.FromSeconds(5));

// Throws OperationCanceledException at the limit.
var paid = await invoices.Get(id).WaitForStateAsync(s => s is Paid, limit.Token);

// In a status stream: the current state first, then each new one.
await foreach (var snapshot in invoices.Get(id).WatchStateAsync(ct))
    await WriteStatusAsync(snapshot.State, snapshot.SequenceNr, ct);

You get the current state first, then a snapshot after each write that holds events, once its Run effects have finished. Every snapshot carries the journal's sequence number as the version of the state, and a slow reader of the stream gets the newest one. This is a live, best-effort push held in memory: nothing is journaled, a state can be missed while the entity restarts or moves, and a reaction that must happen belongs in an effect. Workflow refs have the same two calls, and WaitForOutcome is built on the wait. See Waiting for a state, and watching it.

You do not need to build an outbox. Akka.Durable has one.

// In Decide:
ctx.Persist(new PaymentRecorded(p.Amount))
    .Execute(new PublishPayment(ctx.EntityId, p.Amount));

services.AddEffectHandler<PublishPayment, PublishPaymentHandler>(
    Retry.UntilAcknowledged(
        TimeSpan.FromSeconds(1),
        TimeSpan.FromMinutes(5)));

public sealed class PublishPaymentHandler(IBus bus)
    : IEffectHandler<PublishPayment>
{
    /* ... */
}

PublishPayment is recorded in the same journal write as PaymentRecorded, and its handler runs at least once, after a crash too, until it returns without throwing; it can run more than once, so it must be safe to repeat.

See Effects for the other retry policies, and for Execute without a policy, which is attempted once and tells Decide how it ended. A workflow's work takes the same policies from the same registration: see Workflows.

Getting started

Install the .NET 11 SDK pinned in global.json, then run:

dotnet restore
dotnet build
dotnet test

The solution targets net11.0 and enables preview C# features (C# 15 unions are used throughout). Package versions are managed centrally; Akka.NET packages are pinned to 1.6.0-beta7 (Aaron.Akka.Reminders to 1.6.0-beta5).

Package Contents
Aaron.Akka.Durable Entity definitions, decisions and effects, entity refs, the entity runtime, and Akka.Hosting integration. Everything is in the Akka.Durable namespace.
Aaron.Akka.Durable.TestKit Test helpers built on Akka.Hosting.TestKit, in the Akka.Durable.TestKit namespace

Guide

The rest of the documentation is in docs/, one topic per page. Read it in this order:

Page What it covers
State, commands, events, and replies How to declare an entity's state, commands, events and replies, and what a decision can do.
Effects Execute, the normal way to do outside work, retry policies (the outbox), and the light forms Run, Tell and Send.
Effects with outcomes Effect handlers, answers and give-ups, for work whose result the entity decides on.
Talking to other entities Send and Accepts, for one entity that drives another.
Starting a workflow from an entity Uses, and Start, Notify and Cancel from a decision.
Serialization What is serialized, and how to change stored types safely.
Hosting Local and sharded hosting, passivation and shard count.
Sending commands Entity refs, Ask and Tell, and entity IDs inside messages.
Reading state State-aware refs, and what a state read sees.
Waiting for a state, and watching it WaitForStateAsync and WatchStateAsync, and what a state subscription guarantees.
Workflows Finite processes that start once and end with an outcome: states, work, retry policies on work, the fact table, and workflow refs.
Workflow rules Rules for writing a workflow that stays correct across restarts.
Testing Decisions as plain functions, and the hosted TestKit.
Status and direction What works today and what is not done yet.
Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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.1.0-alpha.8 44 11/13/2026
0.1.0-alpha.7 42 11/13/2026
0.1.0-alpha.6 49 11/12/2026
0.1.0-alpha.5 46 11/11/2026
0.1.0-alpha.4 47 11/11/2026
0.1.0-alpha.3 46 11/10/2026
0.1.0-alpha.2 46 11/10/2026
0.1.0-alpha.1 61 11/7/2026

**Fix: an entity host is no longer refused at start because of another entity's effect.** This fault was new in 0.1.0-alpha.7. Akka.Durable is still a proof of concept, not an official Akka.NET project.

* **The fault.** At host start, each entity type checked every effect handler with no answer, in the whole container. A host that runs one entity type was refused when the container also held a no-answer handler for an effect of another entity type, and the host did not register that other type's serializer. The error named the entity type that was starting, not the one that issues the effect. A test host that runs one entity with a shared set of handlers hit this.
* **At start, an entity type now checks only the effects whose handler answers with its own command type.** Their owner is certain.
* **An effect whose handler has no answer, and that has no serializer of its own,** is refused at the issuing entity's first `Execute` of it, before anything is written. The error names that entity type, the effect and the line to add. A missing `GaveUp` is refused in the same place. This check applies to entities hosted with `WithDurableEntity`.

**What you change from 0.1.0-alpha.7:** nothing. Nothing stored changes.