dispose method

void dispose()

Disposes of all dependencies in the current scope.

This method should be called when the scope is no longer needed to ensure proper resource cleanup.

All registered factories that implements IDisposable will be disposed as well.

Implementation

void dispose() {
  void writeLog(Object instance) {
    log("Disposing", name: "${instance.runtimeType}");
  }

  for (final entry in _instances.values) {
    if (entry.key != this) {
      continue;
    }

    final instance = entry.value;

    if (instance is IDisposable) {
      writeLog(instance);
      instance.dispose();
    } else if (instance is ChangeNotifier) {
      writeLog(instance);
      instance.dispose();
    }
  }
}