简体   繁体   中英

How to use Guard Clauses with Stateless

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;

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM