here is the a brief description : I am working on an MVC application which will manage users requests for a grant. After the user insert the necessary information to create his the demand (which is the main object in my application), his request go through several states, before it will accepted. I was wondering which is the best design pattern that can help in this situation.
-
That looks like a very straightforward program, so the best design pattern is the one you have chosen: request user input, process it and accept it. – eric.m Aug 22 '15 at 10:23
-
Thx for your answer, but the state of the user's demande can change on going through different departments (Actualy 5 states) or rolled back to a subsequent state – chaibi Aug 22 '15 at 10:25
2 Answers
In order to select the best design patterns for the solution there is a lot more information that's needed such as:
- what does the network infrastructure look like ?
- how much server load are we expecting ?
- are transitions between the states manual or more event-driven and automatic ?
- do you need to track and audit the flow of information between the states ?
- ...and the deadline.
... etc
considering what you described, the safest route would definitely require a service bus approach and a workflow engine could not hurt either.
Now, there's so many ways of achieving this and question #1 is really important, however if you just have a web server and nothing else you could look at tools like Hangfire which can work inside the ASP.NET MVC stack.
Hangfire has a cool dashboard as well :)

- 149
- 2
- 7
-
Thank you WaseemS, but I don't want to use any third-party applications.. it's an opportunity for me to take my first steps in the design pattern. To answer your questions, most of the transitions between states are manual which means the user will change the state of the demande after he check the requested information and some other information. Tracking isn't really required.. I am thinking about the satet machine or the satet pattern but I still confused – chaibi Aug 22 '15 at 11:01
-
Under the hood, something like HangFire makes use of the TPL Libraries. you can see more [Here](https://msdn.microsoft.com/en-us/library/dd537609(v=vs.110).aspx) and [here](https://msdn.microsoft.com/en-us/library/hh195051(v=vs.110).aspx) this allows you to fire off tasks on different threads. I would suggest start by just doing FORM POSTS from View to Action before messing in the TPL space. are you using any tools like Entity Framework for your database ? – WaseemS Aug 22 '15 at 11:08
-
If you want to keep track of the state of a request and be able to control state transitions a finite state machine (FSM) will be a good match.
Define your states and the transitions between states. Specify the initial state. Add such an FSM to each request. Trigger transitions as required. You can add meta data to transitions for e.g. authorization requirements (who shall be able to execute this transition).
Each state may have an entry and an exit function to perform specific actions, e.g. logging the transition, forwarding the request for the next check, or triggering the reply in case of 'approved' or 'refused' state.

- 176
- 4
-
Great ! Thank you Mrs Stefan, That's what I am looking for, but could you please provide me with a link to a good example (real world sample) which may help me to understand more this pattern – chaibi Aug 23 '15 at 08:24
-
@chaibi: maybe this [discussion](http://stackoverflow.com/questions/5018391/finite-state-machine-pattern-the-one-true-pattern?rq=1) can help. – Stefan Braun Aug 23 '15 at 20:23