cleanup method

  1. @override
Future<void> cleanup(
  1. Container container
)
override

Optional cleanup method called when container is disposed.

Use this method to perform any necessary cleanup operations such as closing connections or freeing resources.

Implementation

@override
Future<void> cleanup(Container container) async {
  if (!identical(container, _rootContainer)) {
    // Request-scoped cleanup should not tear down application-level watchers.
    return;
  }
  if (_registryListener != null) {
    try {
      final registry = container.get<ConfigRegistry>();
      registry.removeListener(_registryListener!);
    } catch (_) {
      // Ignore if registry is no longer available.
    }
    _registryListener = null;
  }
  await _disposeWatchers();
}