Reputation: 1
I'm new to using Stateless and trying to make sure I understand the purpose of a guard clause. I'm able to create a state machine, but I want to essentially put a check on entering the state where the age > 12 && parent permission exists. Am I understanding Guard clause correctly, and if so, how would I implement such a clause?
var stateMachine = new StateMachine<State, Trigger>(State.EnrollmentCompleted);
stateMachine.Configure(State.EnrollmentCompleted)
.Permit(Trigger.EnrollmentCompleted,ValidatingEnrollment, ***Guardclause to check if user age > 12 and Parentpermission=true***);
return stateMachine;
Upvotes: 0
Views: 1125
Reputation: 3326
There is information on Guard clauses on the GitHub page. Based on that, it looks like it would just be...
stateMachine.Configure(State.EnrollmentCompleted)
.Permit(Trigger.EnrollmentCompleted,ValidatingEnrollment, () => userAge > 12 && parentpermission);
Upvotes: 2