Status Control
Files Referenced in this Document
- MyPluginNameStatus.cs
- MyEntityName.cs
- MyEntityNameAppService.cs
- IMyEntityNameAppService.cs
- MyEntityNameEventHandler.cs
- MyEntityNameConsts.cs
- MyEntityNameEto.cs
Table of Contents
- Introduction
- Status Enum Definition
- Status Management in Entity
- Status Operations in Application Service
- Domain Event Handling Mechanism
- Permission Control and Audit Logs
- Status Transition Business Rules
- State Machine Design Suggestions
- 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:
- Name cannot be empty and length cannot exceed 64 characters.
- Code cannot be empty and length cannot exceed 64 characters.
- Remark length cannot exceed 256 characters.
- Name cannot be duplicated.
- 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:
- State Definition: Use
MyPluginNameStatusas the state of the state machine. - Event Definition: Define events that trigger status transitions (such as Enable, Disable, Complete, etc.).
- Transition Rules: Clarify legal transition paths between states.
- Action Execution: Execute specific business logic before and after status transitions.
- 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.