-
Notifications
You must be signed in to change notification settings - Fork 1
Actions
Action is a Behavior type that simply executes the block of code, accepting input Tokens and producing output Tokens.
Action consists of:
- Unique name that identifies the Action Class,
- Logic - code that is to be executed.
Developers can register a class that implements IActionInterceptor to observe or influence the execution of the Action.
Action definitions can be versioned, ensuring that new versions do not affect already running instances.
Action does not represent any UML model, it is simply a code block. Stateflows Action can be defined directly in Program.cs:
using Stateflows;
using Stateflows.Actions;
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddStateflows(b => b
.AddAction("DatabaseCleanup", async c =>
{
/* database cleanup logic */
})
);Above example Action directly in Program.cs file - it is the simplest way to define it. Yet, for most scenarions it is recommended to define Actions as separate classes:
using Stateflows.Actions;
namespace Example
{
public class DatabaseCleanup : IAction
{
public async Task ExecuteAsync()
{
/* database cleanup logic */
}
}
}...and then register it in Program.cs:
using Stateflows;
using Example;
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddStateflows(b => b
.AddAction<DatabaseCleanup>()
);Type-based definition presented above requires a class that implements the IAction interface.
Action Behavior can be interacted with by sending Events to it. To do this, the Behavior handle must be located using IActionLocator:
using Stateflows;
using Stateflows.Actions;
namespace Example
{
public class DocumentService(IActionLocator locator) // IActionLocator is available via Dependency Injection
{
public Task ApproveAsync(int documentId)
{
if (locator.TryLocateAction(new ActionId("DatabaseCleanup", Random.Shared.Next()), out var databaseCleanup))
{
await databaseCleanup.SendAsync(new Initialize());
}
}
}
}Home page Support Code licensed under an MIT-style License. Documentation licensed under CC BY 4.0. © by Mikołaj Milewski, 2025
Overview
Installation
Behaviors
State Machines
Building blocks
States
State
Composite State
Orthogonal State
Final State
Pseudostates
Choice
Junction
Fork
Join
Transitions
Transition
Default Transition
Internal Transition
Concepts
Evaluation of Transitions
Activities
Building blocks
Nodes
Action Node
Decision Node
Merge Node
Initial Node
Final Node
Input Node
Output Node
Fork Node
Join Node
Accept Event Action Node
Send Event Action Node
Data Store Node
Structured Activity Node
Iterative Activity Node
Parallel Activity Node
Flows
Data Flow
Control Flow
Concepts
Implicit fork and join
Actions