Ilya T
unread,Jan 4, 2012, 1:17:37 AM1/4/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Stateless .NET State Machine Framework
Hi,
I'm trying out Sateless for the first time, and trying to understand
the persistance mechanism. When I'm running the below code, I'm
seeing 3 consecutive calls to GetState(). My concern is if I'm
persisting the state to a database, I don't want unnecessary queries.
Can someone shed light on this? Why is it firing multiple times?
Here's the self contained code, I'm using Stateless off the NuGet
repository (version 2.3.1.1)...
When you run the below code you'll see 3 consecutive calls to
GetState(), then SetState(), then GetState().
class Program
{
public enum State
{
A, B, C
}
public enum Trigger
{
AtoB, BtoC
}
public static State currentState = State.A;
static void Main(string[] args)
{
var machine = new StateMachine<State, Trigger>(() =>
GetState(), s => SetState(s));
machine.Configure(State.A).Permit(Trigger.AtoB, State.B);
machine.Configure(State.B).Permit(Trigger.BtoC, State.C);
machine.Fire(Trigger.AtoB);
Console.ReadLine();
}
private static void SetState(State state)
{
Console.WriteLine("SET state");
currentState = state;
}
private static State GetState()
{
Console.WriteLine("Get state");
return currentState;
}
}