State Machine Module Overview(状态机模块概述)
Business objects often have an associated state specified by their property values (for example, 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.
业务对象通常具有由其属性值指定的关联状态(例如,任务对象具有任务状态,其可以是未开始、进行中等等)。虽然通过修改相应的属性值可以轻松更改此状态,但以统一的方式管理状态转换并非易事。这就是为什么XAF提供了状态机模块,该模块极大地简化了状态转换管理。
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.
在某些情况下,使用SingleChoiceAction动作或一组SimpleAction动作创建自定义控制器,可能比定义编码状态机更简单直接。因此,如果你需要定义一个不应被用户更改的静态状态管理流程,首先考虑这种方法,而不是使用状态机模块。
See Also:
另见:
Add a Simple Action(添加一个简单操作)
Add a Parametrized Action(添加一个参数化操作)
How to: Include an Action to a Detail View Layout(如何:向详细信息视图布局添加操作)
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(添加状态机模块)
In Design Time (For .NET Framework Applications)(在设计时(适用于 .NET Framework 应用程序))
To use the State Machine module in your WinForms or ASP.NET Web Forms 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.
要在WinForms或ASP.NET Web Forms应用程序中使用状态机模块,请使用应用程序设计器添加它。调用应用程序设计器,然后将“StateMachineModule”项从“工具箱”拖到“模块”面板。如果使用实体框架,请将模块的“StateMachineStorageType”属性设置为“DevExpress.Persistent.BaseImpl.EF.StateMachine.StateMachine”,这是运行时创建的状态机的特定于EF的类。在设计器中进行更改后,请务必重新生成解决方案。

In Code (For .NET Applications)(在代码中(适用于 .NET 应用程序))
To add the State Machine module to an ASP.NET Core Blazor or WinForms .NET application, install the DevExpress.ExpressApp.StateMachine NuGet package and register the State Machine module in a platform-agnostic module:
要将状态机模块添加到ASP.NET Core Blazor或WinForms .NET应用程序中,请安装DevExpress.ExpressApp.StateMachine NuGet包,并在与平台无关的模块中注册状态机模块:
C#
public sealed class MySolutionModule : ModuleBase {
//...
public MySolutionModule() {
InitializeComponent();
this.RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.StateMachine.StateMachineModule));
}
}
Note
- You can add modules to your application when you use the Solution Wizard to create a new XAF solution. Select modules in the Choose Additional Modules step.
当你使用解决方案向导创建新的XAF解决方案时,可以向应用程序添加模块。在“选择其他模块”步骤中选择模块。- 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).
要在代码中添加额外的模块,需将其添加到XafApplication.Modules或ModuleBase.RequiredModuleTypes列表中(仅添加对模块程序集的引用是不够的)。- In .NET applications, you can call the AddStateMachine<TBuilder>(IModuleBuilder<TBuilder>, Action<StateMachineOptions>) method in your ASP.NET Core Blazor/WinForms application builder.
在 .NET 应用程序中,你可以在 ASP.NET Core Blazor/WinForms 应用程序生成器中调用 AddStateMachine<TBuilder>(IModuleBuilder<TBuilder>, Action<StateMachineOptions>) 方法。
1713

被折叠的 条评论
为什么被折叠?



