Skip to main content
Version: Next

Status Control

Files Referenced in this Document

Table of Contents​

  1. Introduction
  2. Status Enum Definition
  3. Status Management in Entity
  4. Status Operations in Application Service
  5. Domain Event Handling Mechanism
  6. Permission Control and Audit Logs
  7. Status Transition Business Rules
  8. State Machine Design Suggestions
  9. Conclusion

Introduction​

This document details the implementation of entity enable/disable status management in the system. It focuses on the application of the MyPluginNameStatus enum in the MyEntityName entity and the mechanism for status updates through methods provided by the application service. It also explores domain events triggered during status changes, permission control, operation auditing, and business rule constraints, and proposes state machine design suggestions to support future extensions.

Status Enum Definition​

The MyPluginNameStatus enum defines plugin-related status values used to represent different lifecycle stages. This enum is located in the domain shared layer, ensuring unified usage throughout the system.

Diagram sources

Section sources

Status Management in Entity​

The MyEntityName entity manages its enable/disable status through the IsDisabled property. This property is a nullable boolean type, allowing for more flexible status representation. The entity provides an Update method for modifying basic properties, including status.

Diagram sources

Section sources

Status Operations in Application Service​

The MyEntityNameAppService class implements the IMyEntityNameAppService interface, providing CRUD operations for the MyEntityName entity. Although EnableAsync and DisableAsync methods are not directly implemented in the current code, status change functionality can be achieved through the UpdateAsync method.

Diagram sources

Section sources

Domain Event Handling Mechanism​

When the status of the MyEntityName entity changes, the system responds via the domain event mechanism. MyEntityNameEventHandler implements the IDistributedEventHandler<MyEntityNameEto> interface and can handle events related to MyEntityName.

Diagram sources

Section sources

Permission Control and Audit Logs​

The system uses the permission verification mechanism provided by the ABP framework to control access to status change operations. Although permission checks are not explicitly shown in the current code, the CMSPluginAppService base class inherits from CMSPluginAppService, which typically includes permission verification logic. All status change operations are automatically recorded in audit logs because MyEntityName inherits from FullAuditedAggregateRoot<Guid>, which includes creation and modification timestamps and user information.

Section sources

Status Transition Business Rules​

The current implementation includes the following business rules:

  1. Name cannot be empty and length cannot exceed 64 characters.
  2. Code cannot be empty and length cannot exceed 64 characters.
  3. Remark length cannot exceed 256 characters.
  4. Name cannot be duplicated.
  5. Concurrency tokens need to be checked during status changes.

Regarding the rule "cannot enable already enabled items repeatedly", although not directly implemented, it can be achieved by adding status check logic in the Update method.

Diagram sources

Section sources

State Machine Design Suggestions​

To support the expansion of more status transition scenarios in the future, it is recommended to refactor the current status management logic using the State Machine pattern. A state machine library (such as the StateMachine library) or a custom state machine implementation can be introduced. Suggested state machine design includes:

  1. State Definition: Use MyPluginNameStatus as the state of the state machine.
  2. Event Definition: Define events that trigger status transitions (such as Enable, Disable, Complete, etc.).
  3. Transition Rules: Clarify legal transition paths between states.
  4. Action Execution: Execute specific business logic before and after status transitions.
  5. Persistence: Persist the state machine state to the database.

Diagram sources

Conclusion​

The current system implements basic enable/disable status management through the IsDisabled property and uses the ABP framework's domain event mechanism for status change notifications. Although dedicated EnableAsync and DisableAsync methods are missing, similar functionality can be achieved through the UpdateAsync method. It is recommended to introduce the State Machine pattern in the future to better manage complex status flows and enhance system maintainability and extensibility. At the same time, permission control, audit logs, and business rule validation should be improved to ensure the security and compliance of status changes.