0

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;
pmcilreavy
  • 3,076
  • 2
  • 28
  • 37
Simpsot
  • 1
  • 2

1 Answers1

1

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);
pmcilreavy
  • 3,076
  • 2
  • 28
  • 37