unregister method
Unregister a module with proper cleanup
Implementation
Future<void> unregister(String moduleId) async {
final module = _modules.firstWhereOrNull((m) => m.id == moduleId);
if (module == null) {
debugPrint('ModuleManager: Module $moduleId not found');
return;
}
// Check if other modules depend on this one
final dependents = _modules
.where((m) => m.dependencies.contains(moduleId))
.map((m) => m.id)
.toList();
if (dependents.isNotEmpty) {
throw StateError(
'ModuleManager: Cannot unregister "$moduleId". '
'The following modules depend on it: ${dependents.join(", ")}',
);
}
try {
await module.onDispose(AirDI());
} catch (e, st) {
module.onError(e, st);
}
_modules.removeWhere((m) => m.id == moduleId);
_contexts.remove(moduleId);
// Emit module uninstalled event
EventBus().emit(
ModuleUninstalledEvent(
sourceModuleId: 'system',
uninstalledModuleId: moduleId,
),
);
debugPrint('ModuleManager: Module $moduleId unregistered');
notifyListeners();
}