Trellis.Stateless
3.0.0-alpha.111
See the version list below for details.
dotnet add package Trellis.Stateless --version 3.0.0-alpha.111
NuGet\Install-Package Trellis.Stateless -Version 3.0.0-alpha.111
<PackageReference Include="Trellis.Stateless" Version="3.0.0-alpha.111" />
<PackageVersion Include="Trellis.Stateless" Version="3.0.0-alpha.111" />
<PackageReference Include="Trellis.Stateless" />
paket add Trellis.Stateless --version 3.0.0-alpha.111
#r "nuget: Trellis.Stateless, 3.0.0-alpha.111"
#:package Trellis.Stateless@3.0.0-alpha.111
#addin nuget:?package=Trellis.Stateless&version=3.0.0-alpha.111&prerelease
#tool nuget:?package=Trellis.Stateless&version=3.0.0-alpha.111&prerelease
Stateless State Machine Integration
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-safe —
stateAccessor/stateMutatorare not invoked until firstFireResultorMachineaccess - Configure once — the configuration callback runs exactly once on first access
- Direct access — use
.Machineto access the underlyingStateMachine<TState, TTrigger>forCanFire()checks
How It Works
- Uses Stateless's
CanFire()to check before firing — no try/catch internally - Returns
Result<TState>with the new state on success - Returns a
DomainErroron invalid transitions
Related Packages
- Trellis.Results — Core
Result<T>type - Stateless — State machine library (required dependency)
License
MIT — see LICENSE for details.
| 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
- Stateless (>= 5.16.0)
- Trellis.Results (>= 3.0.0-alpha.111)
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 |