FastFsm.Sharp
0.9.1
dotnet add package FastFsm.Sharp --version 0.9.1
NuGet\Install-Package FastFsm.Sharp -Version 0.9.1
<PackageReference Include="FastFsm.Sharp" Version="0.9.1" />
<PackageVersion Include="FastFsm.Sharp" Version="0.9.1" />
<PackageReference Include="FastFsm.Sharp" />
paket add FastFsm.Sharp --version 0.9.1
#r "nuget: FastFsm.Sharp, 0.9.1"
#:package FastFsm.Sharp@0.9.1
#addin nuget:?package=FastFsm.Sharp&version=0.9.1
#tool nuget:?package=FastFsm.Sharp&version=0.9.1
FastFsm
Source-generated finite and hierarchical state machines for .NET 10.
FastFsm generates switch-based state-machine code at build time. Machines can be configured with either the Fluent API or the Attribute API. The generator validates transitions, guards, callbacks, and hierarchy during compilation.
Repository package version: 0.9.1 (defined in Directory.Build.props). See CHANGELOG.md. 0.9.1 is on NuGet.org as FastFsm.Sharp*, with legacy FastFsm.Net* metapackages forwarding to the same bits.
Install
dotnet add package FastFsm.Sharp
# optional
dotnet add package FastFsm.Sharp.Logging
dotnet add package FastFsm.Sharp.DependencyInjection
Requires .NET SDK 10.0 (see global.json).
Configuration APIs
Both APIs use the same generator and runtime.
Fluent API
using Abstractions.Fluent;
using Abstractions.Attributes;
public enum DoorState { Closed, Open }
public enum DoorTrigger { Open, Close }
[StateMachine(typeof(DoorState), typeof(DoorTrigger))]
public partial class DoorController
{
private void Configure() => FSM
.State(DoorState.Closed)
.On(DoorTrigger.Open).GoTo(DoorState.Open)
.State(DoorState.Open)
.On(DoorTrigger.Close).GoTo(DoorState.Closed);
}
See docs/fluent-api.md.
Attribute API
using Abstractions.Attributes;
public enum DoorState { Closed, Open }
public enum DoorTrigger { Open, Close }
[StateMachine(typeof(DoorState), typeof(DoorTrigger))]
public partial class DoorController
{
[Transition(DoorState.Closed, DoorTrigger.Open, DoorState.Open)]
[Transition(DoorState.Open, DoorTrigger.Close, DoorState.Closed)]
private void ConfigureTransitions() { }
}
For either form, create the generated machine with an initial state, call Start(), then use Fire() or TryFire():
var door = new DoorController(DoorState.Closed);
door.Start();
door.Fire(DoorTrigger.Open); // throws when no valid transition exists
bool ok = door.TryFire(DoorTrigger.Close); // returns false when no valid transition exists
Features
- Compile-time validation of state-machine definitions
- Synchronous and asynchronous machines (
ValueTaskon asynchronous paths) - Hierarchical states, shallow and deep history, internal transitions, and transition priority
- Typed payloads per trigger
IStateMachineExtensiontransition hooks- Optional logging through
FastFsm.Sharp.Logging - Optional dependency-injection integration through
FastFsm.Sharp.DependencyInjection - Generated code paths compatible with trimming and Native AOT
Documentation
| Topic | Guide |
|---|---|
| Setup and first machine | docs/getting-started.md |
| Fluent API | docs/fluent-api.md |
| Attribute API | docs/attribute-api.md |
| Hierarchical machines | docs/hsm.md |
| Async | docs/async.md |
| Payloads | docs/payloads.md |
| Extensions | docs/extensions.md |
| Logging | docs/logging.md |
| Dependency injection | docs/dependency-injection.md |
| Diagnostics (FSM0100–FSM3083) | docs/diagnostics.md |
| Architecture | docs/architecture.md |
| Benchmarks | docs/benchmarks.md |
| Changelog | CHANGELOG.md |
| Roadmap | ROADMAP.md |
Packages
| Package | Purpose |
|---|---|
FastFsm.Sharp |
Runtime and source generator |
FastFsm.Sharp.Logging |
ILogger integration for generated machines |
FastFsm.Sharp.DependencyInjection |
Microsoft.Extensions.DependencyInjection registration helpers |
Migrating from FastFsm.Net 0.6.9.x: new projects use FastFsm.Sharp*. Existing FastFsm.Net* references can stay — 0.9.0 ships legacy metapackages that forward to FastFsm.Sharp* (see CHANGELOG.md). Your machine code (Abstractions.*, FastFsm.*) stays the same. Details: docs/architecture.md.
Repository layout
src/Fsm/Fsm.Core/— runtime packaged asFastFsm.Sharpsrc/Abstractions/— attributes and Fluent API definitionssrc/Generator/— Roslyn source generator (Generator.Core,Generator.Model,Generator.Rules, …)src/Generator/Generator.Rules/— diagnostic rule definitions (RuleIdentifiers,DefinedRules)src/Fsm/Fsm.Tests/Tests.Machines/— shared machine definitions used byTests.FsmandTests.Loggingsrc/Fsm/Fsm.Tests/Tests.*/— FSM test runners (Tests.Fsm,Tests.Async,Tests.Logging, …)src/Generator/Generator.Tests/Tests.SourceGenerators/— generator rule and emission tests
Contributing
Build and test from a clean tree. With UsePackages=false, test projects use project references rather than a pre-built package from ./nuget.
dotnet test FastFsm.slnx -c Release
That runs Tests.Fsm, Tests.Async, Tests.Logging, Tests.DependencyInjection, Tests.Instance, and Tests.SourceGenerators. Tests.Machines is a shared machine library, not a test runner.
Pack the three NuGet packages and compile clean consumer consoles against ./nuget:
# Windows
./scripts/pack-and-smoke.ps1
# Linux / macOS
bash ./scripts/pack-and-smoke.sh
CI for pull requests runs on GitHub-hosted runners (.github/workflows/ci.yml). Self-hosted Windows/Linux/macOS jobs run only on push to main and workflow_dispatch (.github/workflows/ci-self-hosted.yml).
See docs/architecture.md for the generator layout.
License
MIT — see LICENSE.
| 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
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on FastFsm.Sharp:
| Package | Downloads |
|---|---|
|
FastFsm.Net
Legacy package ID. Depends on FastFsm.Sharp, which contains the runtime, Abstractions, and Roslyn analyzers. New projects should reference FastFsm.Sharp directly. |
|
|
FastFsm.Sharp.DependencyInjection
Dependency injection support for FastFsm.Sharp state machines. Enables logging generation. |
|
|
FastFsm.Sharp.Logging
Logging support for FastFsm.Sharp state machines (ILogger). |
GitHub repositories
This package is not used by any popular GitHub repositories.
.NET 10. Extension generation is opt-in. Warning-free generated code for typical machines. See CHANGELOG.md.