Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get advantage of stateless framework
    primarykey
    data
    text
    <p>I would like to use <a href="http://code.google.com/p/stateless" rel="nofollow noreferrer">http://code.google.com/p/stateless</a> in my code to separate the functionality from its dependencies. I didn't find any advanced examples of the usage, so this question is about stateless framework best practices.</p> <p>I have following configuration (this is just example, has only one function state): </p> <pre><code>var stateMachine = new StateMachine(State.Stopped); stateMachine.Configure(State.Stopped) .Permit(Trigger.Failed, State.Error) .Permit(Trigger.Succeed, State.GenerateMachineData); stateMachine.Configure(State.GenerateMachineData) .Permit(Trigger.Failed, State.Error) .Permit(Trigger.Succeed, State.Finished); public enum State { Stopped, GenerateMachineData, Finished, Error } public enum Trigger { Succeed, Failed } </code></pre> <p>where to call the actual functionality then. I had following ideas but each of them has advantages and disadvantages:</p> <p><strong>1) Set the functionality as well as next fire in OnEntry():</strong></p> <pre><code>stateMachine.Configure(State.GenerateMachineData) .OnEntry(() => { try { Generate(); stateMachine.Fire(Trigger.Succeed); } catch { stateMachine.Fire(Trigger.Error); } }) .Permit(Trigger.Failed, State.Error) .Permit(Trigger.Succeed, State.Finished); </code></pre> <p>so then if I just call </p> <pre><code>stateMachine.Fire(Trigger.Succeed); </code></pre> <p>it ends up either in State.Finished or State.Error</p> <ul> <li>advantages - all together</li> <li>disadvatages - the solution cant be really unittested</li> </ul> <p><strong>2) have statemachine and functionality separated like:</strong> <code><pre> void DoTheStuff() { switch (stateMachine.State) { State.Stopped: stateMachine.Fire(State.Succeed); break; State.GenerateMachineData: Generate(); stateMachine.Fire(State.Succeed); break; default: throw new Exception(); } }</p> <p>void Main() { while (stateMachine.State != State.Succeed &amp;&amp; stateMachine.State != State.Error) { DoTheStuff(); } } </code></pre></p> <ul> <li>advantages: the statemachine can be tested itself</li> <li>disadvantages: I quite don't like it</li> </ul> <p><strong>3) some other solution?</strong></p> <p>I will be glad for any answer</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload