When an organization policy is created or updated via ISavePolicyCommand, the system executes an ordered sequence of steps. You can hook into these steps by implementing specific IPolicyUpdateEvent interfaces. If no handler is implemented, the policy is simply upserted to the database with an audit log event.
The workflow sequence is:
- Validate organization can use policies
- Validate policy dependencies (via
IEnforceDependentPoliciesEvent) - Run policy-specific validation (via
IPolicyValidationEvent) - Execute pre-save side effects (via
IOnPolicyPreUpdateEvent) - Upsert policy + log event
- Execute post-save side effects (via
IOnPolicyPostUpdateEvent)
Important Limitation: The workflow is not atomic. If an exception occurs at any step, changes made by prior steps (like pre-save side effects) are not automatically rolled back.
SaveAsync()
├─ 1. Validate organization can use policies
├─ 2. Validate policy dependencies ← IEnforceDependentPoliciesEvent
├─ 3. Run policy-specific validation ← IPolicyValidationEvent
├─ 4. Execute pre-save side effects ← IOnPolicyPreUpdateEvent
├─ 5. Upsert policy + log event
└─ 6. Execute post-save side effects ← IOnPolicyPostUpdateEvent