State Machine Module Overview
- 3 minutes to read
Business objects often have an associated state specified by their property values (e.g., the Task object has Task.Status, which can be NotStarted, InProgress, etc.). While this state can easily be changed by modifying corresponding property values, managing state transitions in a uniform way is not that simple. This is why XAF ships with the State Machine module, which greatly simplifies state transition management.
State Machine Capabilities
The module creates a set of Actions that correspond to state transitions and display them in corresponding Views.
With the State Machine, you can:
- define a set of states and corresponding transitions, and associate them with a business class. You can do this in code or at runtime, as the State Machine module comes with predefined Views for state and transition management. The property whose values specify different object states can be either an enumeration-typed property or a reference property;
- define Conditional Appearance rules and associate them with particular states. This can also be done both in code and at runtime.
Important
In certain scenarios, creating a custom Controller with the SingleChoiceAction Action or a set of SimpleAction Actions can be simpler and more straightforward than defining a coded State Machine. So, if you need to define a static state management process that should not be changed by users, consider this approach first instead of using the State Machine module.
See Also:
Note
In the DataView, ServerView, InstantFeedback, and InstantFeedbackView data access modes, State Machine requests selected objects from the database each time the selection is changed.
Add the State Machine Module
To use the State Machine module in your WinForms or ASP.NET application, add it by using the Application Designer. Invoke the Application Designer and drag the StateMachineModule item from the Toolbox to the Modules panel. If you use Entity Framework, set the Module’s StateMachineStorageType property to DevExpress.Persistent.BaseImpl.EF.StateMachine.StateMachine - the EF-specific class for state machines created at runtime. Be sure to rebuild your solution after making changes in the Designer.
Note
You can add modules to your application when you create a new XAF solution using the Solution Wizard. To do this, select modules in the Choose Extra Modules step.
- To add an extra module in code, add it to the XafApplication.Modules or ModuleBase.RequiredModuleTypes list (adding a reference to the module assembly is insufficient).