statemachine
statemachine copied to clipboard
Extension.EnteredInitialState has context.State == null
This prevents getting the IState<TState, TEvent>
of the initial status.
Example extension code:
private class CurrentStatusExtension : AsyncExtensionBase<States, Triggers>
{
private readonly AppccelerateTestData _instance;
public CurrentStatusExtension(AppccelerateTestData instance)
{
_instance = instance;
}
public override void EnteredInitialState(
IStateMachineInformation<States, Triggers> stateMachine,
States state,
ITransitionContext<States, Triggers> context)
{
// context.State is null ... so there is no way to get the initial state?
_instance.CurrentStatus = context.State;
}
}
Use the state passed to the method directly. The state of the context is the source state, which is null in case of initialization.
Does this work for you?
No, sorry, I need the IState, because I need to get the valid triggers.
I see.
That can be accomplished by changing the code in the method Appccelerate.StateMachine.AsyncMachine.StateMachine.Initialize
on line 193 so that it passes the IState
to the extension (the same value is already passed to a method the line before).
If you want the change quickly, I suggest you change the code as explained above and compile the state machine on your own. Otherwise, you'll have to wait for me and my time is very limited at the moment.
See http://www.appccelerate.com/howtocontributewalkthrough.html for an explanation how to get your own nuget package easily from our build infrastructure through a pull request.
I hope that helps. Urs
Maybe it might be useful to add a property containing the target state? My assumption was that the context state always contains the target state for all transitioned/initialized events.