Transito 1.0.0

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

Transito

A generic enum state machine library for .NET that provides attribute-based configuration and fluent builders for managing state transitions.

Features

  • Attribute-based Configuration: Define state machines using simple attributes on your enums
  • Fluent Builder Pattern: Programmatically configure state machines with a fluent API
  • State Categorization: Organize states into categories (Initial, Active, Final, etc.)
  • Extension Methods: Easy-to-use extension methods for common state operations
  • Thread-safe: Built with concurrent collections for safe multi-threaded usage
  • High Performance: Cached state machine instances for optimal performance

Installation

dotnet add package Transito

Quick Start

Attribute-based Configuration

using Transito.Attributes;

[StateMachine(InitialState = OrderStatus.Draft)]
public enum OrderStatus
{
    [StateCategory(StateCategory.Initial)]
    [AllowTransitionsTo(Submitted, Cancelled)]
    Draft,

    [StateCategory(StateCategory.Active)]
    [AllowTransitionsTo(Processing, Cancelled)]
    Submitted,

    [StateCategory(StateCategory.Active)]
    [AllowTransitionsTo(Shipped, Cancelled)]
    Processing,

    [StateCategory(StateCategory.Active)] 
    [AllowTransitionsTo(Delivered)]
    Shipped,

    [StateCategory(StateCategory.Final)]
    Delivered,

    [StateCategory(StateCategory.Final)]
    Cancelled
}

// Usage
var order = OrderStatus.Draft;

// Check valid transitions
bool canSubmit = order.CanTransitionTo(OrderStatus.Submitted); // true
bool canDeliver = order.CanTransitionTo(OrderStatus.Delivered); // false

// Get all valid transitions
var validTransitions = order.GetValidTransitions(); // [Submitted, Cancelled]

// Check state categories
bool isInitial = order.IsInitialState(); // true
bool isFinal = order.IsFinalState(); // false

Fluent Builder Pattern

using Transito.Builders;

var stateMachine = StateMachineBuilder<OrderStatus>
    .Configure()
    .Allow(OrderStatus.Draft).To(OrderStatus.Submitted, OrderStatus.Cancelled)
    .Allow(OrderStatus.Submitted).To(OrderStatus.Processing, OrderStatus.Cancelled)
    .Allow(OrderStatus.Processing).To(OrderStatus.Shipped, OrderStatus.Cancelled)
    .Allow(OrderStatus.Shipped).To(OrderStatus.Delivered)
    .Allow(OrderStatus.Delivered).ToNone()
    .Allow(OrderStatus.Cancelled).ToNone()
    .AddStateToCategory(OrderStatus.Draft, StateCategory.Initial)
    .AddStateToCategory(OrderStatus.Delivered, StateCategory.Final)
    .AddStateToCategory(OrderStatus.Cancelled, StateCategory.Final)
    .WithInitialState(OrderStatus.Draft)
    .Build();

// Use the state machine
bool canTransition = stateMachine.CanTransitionTo(OrderStatus.Draft, OrderStatus.Submitted);
var initialState = stateMachine.GetInitialState();

Available Attributes

  • [StateMachine] - Marks an enum as a state machine
  • [AllowTransitionsTo(...)] - Defines valid transitions from a state
  • [StateCategory(...)] - Categorizes states (Initial, Active, Final, Intermediate, Error, Retry)

Extension Methods

  • CanTransitionTo(newState) - Check if transition is valid
  • GetValidTransitions() - Get all possible transitions
  • IsInCategory(category) - Check if state belongs to category
  • IsFinalState() - Check if state is final
  • IsInitialState() - Check if state is initial
  • IsActiveState() - Check if state is active

State Categories

  • Initial - Starting states
  • Active - States representing ongoing processes
  • Final - Terminal states with no further transitions
  • Intermediate - Temporary transition states
  • Error - Error states
  • Retry - States that allow retry operations

License

MIT License - see LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.
  • net9.0

    • No dependencies.

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
1.0.0 142 7/26/2025