Skip to content

Commit 269fff4

Browse files
feat: Standardize module lifecycle and cleanup
Co-authored-by: hongwei.xi <hongwei.xi@myob.com>
1 parent 0abd5d7 commit 269fff4

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Change: Standardize module lifecycle and cleanup
2+
3+
## Why
4+
- Module lifecycle lacks a clear Loaded/Active/Error state machine; initialization can run without a bound host, causing inconsistent state.
5+
- Detail pages are eagerly loaded; this increases startup cost and risks failures before the user navigates.
6+
- Unload/disable paths are inconsistent, leaving menus/navigation/messages and scoped resources registered, causing leaks and unstable hot-reload.
7+
8+
## What Changes
9+
- Define a runtime module state machine with explicit transitions: Loaded (metadata/menus ready, host not bound), Active (initialized with host), Error (failed init or detail load) plus retry rules.
10+
- Default to menu-only load; lazily load and render module detail on first navigation with async flow and cancellation/timeout handling.
11+
- Gate initialization on host binding; when a host binds, batch-initialize eligible modules and persist state transitions.
12+
- Standardize unload/disable cleanup: invoke module deregistration hooks (menu/navigation/message), dispose scoped providers and caches, and unload the module AssemblyLoadContext.
13+
14+
## Impact
15+
- Affected specs: runtime
16+
- Affected code: module runtime loader/state manager, navigation/detail loader, host bind/unbind flow, module cleanup pipeline
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## ADDED Requirements
2+
3+
### Requirement: Standardized module lifecycle states and lazy activation
4+
Runtime modules SHALL follow a Loaded/Active/Error state machine, gate initialization on host binding, and lazily activate detail views.
5+
6+
#### Scenario: Host not bound keeps module Loaded
7+
- **WHEN** a module is discovered/installed and the host is not yet bound
8+
- **THEN** the runtime loads manifest/menu metadata only
9+
- **AND** marks the module state as `Loaded`
10+
- **AND** defers module initialization, services, and detail view creation.
11+
12+
#### Scenario: Host binding activates eligible modules
13+
- **WHEN** the host binds
14+
- **THEN** the runtime initializes all Ready+enabled modules using the lifecycle pipeline
15+
- **AND** updates their state to `Active` upon success
16+
- **AND** records diagnostics for any module that fails to activate.
17+
18+
#### Scenario: Lazy detail load on first navigation
19+
- **WHEN** a user first navigates to a module’s detail view
20+
- **THEN** the runtime asynchronously loads and renders the module detail/page
21+
- **AND** supports cancellation/timeout for the detail load
22+
- **AND** surfaces errors and sets the module state to `Error` if detail load fails.
23+
24+
#### Scenario: Initialization failure transitions to Error
25+
- **WHEN** module initialization or detail load fails
26+
- **THEN** the module state becomes `Error`
27+
- **AND** diagnostics are recorded for recovery
28+
- **AND** the module is not reused until a retry/repair is attempted.
29+
30+
### Requirement: Unified unload and cleanup pipeline
31+
Runtime modules MUST expose and execute a standardized cleanup path on unload/disable to remove registrations and release resources.
32+
33+
#### Scenario: Unload cleans registrations and resources
34+
- **WHEN** a non-system module is unloaded or disabled
35+
- **THEN** the runtime invokes module-provided deregistration hooks for menus/navigation/messages/subscriptions
36+
- **AND** disposes the module-scoped ServiceProvider, caches, and other scoped resources
37+
- **AND** removes the module’s UI/navigation projections from the host
38+
- **AND** unloads the module AssemblyLoadContext and returns the module to the `Loaded` state (metadata only).
39+
40+
#### Scenario: System modules protected from unload
41+
- **WHEN** an unload is requested for a system module
42+
- **THEN** the runtime rejects the request with a clear diagnostic.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## 1. Implementation
2+
- [ ] 1.1 Define Loaded/Active/Error state machine with diagnostics and persistence
3+
- [ ] 1.2 Add lazy detail load/render flow (async, cancel/timeout, error to state)
4+
- [ ] 1.3 Gate initialization on host binding; batch activate eligible modules
5+
- [ ] 1.4 Implement standardized unload cleanup (menus/navigation/messages, scoped resources, ALC)
6+
- [ ] 1.5 Add tests/telemetry for state transitions, lazy load, and cleanup paths

0 commit comments

Comments
 (0)