unregister<T> method
Unregisters a dependency of type T.
If ownership tracking is enabled, callerModuleId must match the original owner
to perform the unregistration. Returns true on success.
callerModuleId Optional ID of the module attempting to unregister the service.
Implementation
bool unregister<T>({String? callerModuleId}) {
final owner = _registrationOwners[T];
// Ownership check: Verify that only the owner can unregister
if (owner != null && callerModuleId != null && owner != callerModuleId) {
AirLogger.warning(
'Unauthorized unregister attempt',
context: {
'type': T.toString(),
'owner': owner,
'caller': callerModuleId,
},
);
AirAudit().log(
type: AuditType.securityViolation,
action: 'unauthorized_unregister',
moduleId: callerModuleId,
context: {'type': T.toString(), 'owner': owner},
severity: AuditSeverity.medium,
success: false,
);
return false;
}
_registrations.remove(T);
_registrationOwners.remove(T);
AirLogger.debug('Unregistered', context: {'type': T.toString()});
return true;
}