Trellis.Stateless 3.0.0-alpha.135

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

Stateless State Machine Integration

NuGet Package

Wraps the Stateless library's Fire() method to return Result<TState> instead of throwing on invalid transitions.

Installation

dotnet add package Trellis.Stateless

Quick Start

using Stateless;
using Trellis;
using Trellis.Stateless;

var machine = new StateMachine<OrderState, OrderTrigger>(OrderState.New);
machine.Configure(OrderState.New)
    .Permit(OrderTrigger.Submit, OrderState.Submitted);

// Returns Result<OrderState> — no exceptions on invalid transitions
Result<OrderState> result = machine.FireResult(OrderTrigger.Submit);
// result.IsSuccess == true, result.Value == OrderState.Submitted

Result<OrderState> invalid = machine.FireResult(OrderTrigger.Cancel);
// invalid.IsFailure == true, invalid.Error is DomainError

LazyStateMachine

Aggregates with state machines face a materialization problem with ORMs like EF Core: the parameterless constructor runs before properties are populated, so a stateAccessor lambda like () => Status reads a default or uninitialized value — reference-type states throw, while enum states silently start the machine in the wrong state. LazyStateMachine<TState, TTrigger> defers machine construction until first use:

public class Order : Aggregate<OrderId>
{
    private readonly LazyStateMachine<OrderStatus, string> _machine;

    public OrderStatus Status { get; private set; }

    public Order()
    {
        _machine = new LazyStateMachine<OrderStatus, string>(
            () => Status,
            s => Status = s,
            ConfigureStateMachine);
    }

    public Result<Order> Submit() =>
        _machine.FireResult("submit")
            .Map(_ => this);

    private static void ConfigureStateMachine(StateMachine<OrderStatus, string> machine)
    {
        machine.Configure(OrderStatus.Draft)
            .Permit("submit", OrderStatus.Submitted);
    }
}
  • Constructor-safestateAccessor/stateMutator are not invoked until first FireResult or Machine access
  • Configure once — the configuration callback runs exactly once on first access
  • Direct access — use .Machine to access the underlying StateMachine<TState, TTrigger> for CanFire() checks

How It Works

  • Calls Stateless's Fire() directly and wraps known invalid-transition InvalidOperationExceptions in a DomainError
  • Returns Result<TState> with the new state on success
  • Preserves exceptions from user entry, exit, or transition actions instead of swallowing them
  • Inherits Stateless thread-safety constraints — do not call FireResult(...) concurrently on the same machine instance without external synchronization

License

MIT — see LICENSE for details.

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
3.0.0-alpha.140 0 3/30/2026
3.0.0-alpha.137 48 3/27/2026
3.0.0-alpha.135 29 3/26/2026
3.0.0-alpha.127 36 3/23/2026
3.0.0-alpha.123 37 3/19/2026
3.0.0-alpha.118 50 3/14/2026
3.0.0-alpha.111 38 3/12/2026
3.0.0-alpha.104 39 3/9/2026
3.0.0-alpha.100 41 3/4/2026
3.0.0-alpha.99 43 3/4/2026
3.0.0-alpha.98 39 3/3/2026
3.0.0-alpha.95 43 3/2/2026
3.0.0-alpha.94 44 3/2/2026
3.0.0-alpha.93 42 3/1/2026
3.0.0-alpha.92 54 2/28/2026
3.0.0-alpha.83 46 2/27/2026