initialize method
Initializes the module and transitions it to active state.
This method is called automatically when the module is first loaded.
Override onInit
to perform custom initialization logic.
Throws:
ModuleException
if initialization fails- StateError if the module is not in uninitialized state
Implementation
Future<void> initialize() async {
await _transitionTo(ModuleLifecycleState.initializing);
try {
info('Initializing module $name');
await onInit();
await _transitionTo(ModuleLifecycleState.active);
info('Module $name initialized successfully');
} catch (e) {
error('Failed to initialize module $name: $e');
await _transitionTo(ModuleLifecycleState.error, error: e);
rethrow;
}
}