onDispose method
Resource cleanup when the module is being removed.
This method is called by ModuleManager.unregister. It handles:
- Automatic cancellation of EventBus subscriptions for this module.
- Automatic unregistration of SecureServiceRegistry services.
Note: Always call super.onDispose(di) if you override this.
di The dependency injection container instance.
Implementation
@mustCallSuper
Future<void> onDispose(AirDI di) async {
_state = ModuleLifecycleState.disposing;
debugPrint('[$id] onDispose');
// Clean up event subscriptions
EventBus().cancelModuleSubscriptions(id);
// Clean up services
SecureServiceRegistry().unregisterModuleServices(id);
_state = ModuleLifecycleState.disposed;
}