.NET 无状态多重 PermitIf
.NET stateless multiple PermitIf
我需要在我的 .Net Stateless state machine 中为某个状态添加多个守卫。
考虑以下模拟场景。如果满足两个条件,我只能允许从插入到修改:
_sm.Configure(State.Insert)
.PermitReentry(Trigger.Insert)
.PermitIf(Trigger.Modify, State.Modified, Condition1, "Only permitted when condition 1 true")
.PermitIf(Trigger.Modify, State.Modified, Condition2, "Only permitted when condition 2 true")
.Permit(Trigger.Cancel, State.Canceled)
在上面的代码中,只评估了第一个条件。
我也可以将两个条件捆绑到一个条件中,在一个 PermitIf 中传递它,但我宁愿不这样做:
.PermitIf(Trigger.Modify, State.Modified, BundledCondition, "Only permitted when bundled condition is true")
有没有办法在 dotnet-state-machine 中实现多个守卫?
我认为这不可能。特别是在阅读文档中的这个声明之后:
Guard clauses within a state must be mutually exclusive (multiple
guard clauses cannot be valid at the same time.)
我想将所有条件捆绑在 only guard 中是可行的方法。
我需要在我的 .Net Stateless state machine 中为某个状态添加多个守卫。
考虑以下模拟场景。如果满足两个条件,我只能允许从插入到修改:
_sm.Configure(State.Insert)
.PermitReentry(Trigger.Insert)
.PermitIf(Trigger.Modify, State.Modified, Condition1, "Only permitted when condition 1 true")
.PermitIf(Trigger.Modify, State.Modified, Condition2, "Only permitted when condition 2 true")
.Permit(Trigger.Cancel, State.Canceled)
在上面的代码中,只评估了第一个条件。 我也可以将两个条件捆绑到一个条件中,在一个 PermitIf 中传递它,但我宁愿不这样做:
.PermitIf(Trigger.Modify, State.Modified, BundledCondition, "Only permitted when bundled condition is true")
有没有办法在 dotnet-state-machine 中实现多个守卫?
我认为这不可能。特别是在阅读文档中的这个声明之后:
Guard clauses within a state must be mutually exclusive (multiple guard clauses cannot be valid at the same time.)
我想将所有条件捆绑在 only guard 中是可行的方法。