During this weekend I found my old 1.1 project for handling flows in web applications. The main idea of the project was to make it easy to create and change a flow of pages. For example if I want to start a workflow to create a user, I could specify the flow in the web.config like this:
<workflow>
<flow name=”CreateUser”>
<view name=”AddUser” view=”adduser.aspx” controllerType=”...UserController”/>
<view name=”ConfirmAddser” view=”confirmuser.aspx”.../>
</flow>
</workflow>
The flow above will first show a view with a form to enter user information; the next step is to confirm the information before the user is saved. If I decided to create one more step in the flow, I could easy add it to the configuration file without changing any code in my app:
<flow name=”CreateUser”>
<view name=”AddUser” view=”adduser.aspx” controllerType=”...UserController”/>
<view name=”AddUSerToRole” view=”addusertorole.aspx” .../>
<view name=”ConfirmAddUser” view=”confirmuser.aspx” .../>
</flow>
To start a flow from a page I simply wrote:
viewWorklow.Start(“CreateUser”);
It will automatically redirect me to the first node in the flow with the name “CreateUser”. I could then in my controllers for each view move to the next step in my flow by calling the MoveNext method:
viewWorkflow.MoveNext();
If I wanted to jump to a specific step in the flow, I could pass the name of the view into a MoveTo method, for example in the flow above I maybe don’t want to add a user to a specific role at a specific circumstance.
viewWorkFlow.MoveTo(“ConfirmAddUser”);
If I wanted to start a flow within a flow, I have two way of doing that; the first one is in the configuration file by using the <executeFlow> element inside of a flow, or just call the ExecuteFlow method (The different between the Start method and ExecuteFlow, is that the ExecuteFlow will keep the stat of the flow, the Start will be used to start a new “session” of a workflow.).
<flow name=”CreateUser”>
<view name=”AddUser” view=”adduser.aspx” controllerType=”...UserController”/>
<executeFlow name=”AddUserToRole” />
<view name=”ConfirmAddUser” view=”confirmuser.aspx” .../>
</flow>
<flow name=” AddUserToRole”>
<view name=” AddUser” view=”addusertorole.aspx” .../>
</flow>
or
viewWorkflow.ExecuteFlow(“AddUserToRole”);
When the MoveNext method finds that the next node in the flow is a new workflow, it will start that flow and keep the state of the current view.
With this framework I could easily create a flow and I could avoid changing any code in my app if I needed to change the flow. This framework uses controllers to separate the logic from the Views and also handle the navigation and state. By not using the MoveNext mehthod, this can still be used to automatically instantiate a controller for a View, instead of manually do it as I mentioned last in my post Model View Presenter - Use test against Views in ASP.Net part 2
I’m thinking of cutting this out from my existing .Net 1.1 application, and make it as a separate project and convert it to .Net 2.0. Could this be something that you could use in your apps in that case?