didAttachToScope method

  1. @override
  2. @mustCallSuper
void didAttachToScope(
  1. LevitScope scope, {
  2. String? key,
})
inherited

Attaches this controller to an owning scope with an optional registration key.

This method is called by the DI runtime when the controller is resolved. It updates ownership metadata for already tracked reactive resources so diagnostics and disposal ownership remain accurate.

Throws no exceptions intentionally; internal failures are logged.

Implementation

@override
@mustCallSuper
void didAttachToScope(LevitScope scope, {String? key}) {
  _scope = scope;
  _registrationKey = key;

  // Attachment may happen after reactive creation; ownership must be reconciled.
  if (key != null) {
    _cachedOwnerPath = null; // Force recalculation if key changed
    try {
      refreshOwnedReactivePaths();
    } catch (e, s) {
      dev.log(
        'LevitController: failed to refresh auto-linked reactive',
        name: 'levit_dart',
        error: e,
        stackTrace: s,
      );
    }
  }
}