R – Is it a good idea to run workflows created using windows workflow foundation in asp.net mvc environment

asp.net-mvcstate-machine-workflow

I'm running a state machine workflow to control user interactions with the website. The workflow runtime is hosted in asp.net. I was able to get it to work as I wanted it to but still the event fired to transition a state in the workflow doesn't always transition the state. This makes me question the integration of WWF with asp.net:

Is hosting workflow runtime in asp.net mvc environment the best choice?

Or is it better to host the runtime in a windows service using Windows Workflow Service Host and allow asp.net application access it through WCF?

Are there any success stories out there that anybody would like to share?

Any comments and suggestions are welcome,

Thanks,

Cullen

Best Answer

I have an alternative for you if you are open to a non-Microsoft solution, although it is .Net based. I have used a framework called Stateless, a state-machine by Nicholas Blumhardt - creator of Autofac- where you can do the following:

Stateless has been designed with encapsulation within an ORM-ed domain model in mind. Some ORMs place requirements upon where mapped data may be stored. To this end, the StateMachine constructor can accept function arguments that will be used to read and write the state values:

var stateMachine = new StateMachine<State, Trigger>(
    () => myState.Value,
    s => myState.Value = s);

With very little effort you can persist your state, then retrieve that state easily later on. Notice that you have NO need to host a separate runtime environment. If you state is represented by an integer, you can fetch that value, instantiate a Stateless object with the current state and you now are ready to update your state machine. The beauty is that you do not need the overhead that normally is required of Workflow Foundation.

I have used this in production for 4 months and it works very well. I think you could adapt this quite easily to ASP.Net MVC.


In respect updating the workflow dynamically, if you configure a state machine such as

var stateMachine = new StateMachine<string, int>();

and maintain a separate file of states and triggers in XML, you can perform a configuration at runtime by looping through the string int value pairs.

Related Topic