destroy method

void destroy()

Runs the destroy callbacks of every instance, newest first (later beans may use earlier ones), and empties the scope. The scope stays usable: the next lookup creates fresh instances.

Implementation

void destroy() {
  // Reverse insertion order: beans created later may depend on earlier
  // ones, so they go first.
  final names = _objects.keys.toList().reversed;
  for (final name in names) {
    _callbacks.remove(name)?.call();
    _objects.remove(name);
  }
}