children method
Retrieves an iterable of child DI instances.
Only returns already-materialised children. A Lazy<DI> whose
singleton has never been read is skipped — otherwise iterating
children() (called from _maybeFinish on every register) would
force-construct every registered child container on every parent
registration, defeating laziness and running child constructors at
the wrong time.
The result is snapshotted via .toList() so callers can safely
iterate even if a re-entrant register/unregister mutates the underlying
registry mid-walk. Without the snapshot, _maybeFinish (which iterates
children() on every register) would throw ConcurrentModificationError
if any onRegister callback registered another dep on the same container.
Implementation
Option<Iterable<DI>> children() {
return childrenContainer.map(
(e) => e.registry.unsortedDependencies
.toList(growable: false)
.map(_childFromDep)
.nonNulls,
);
}