registerChild method

Resolvable<Lazy<DI>> registerChild({
  1. Entity groupEntity = const DefaultEntity(),
})
inherited

Registers a fresh child DI container under groupEntity. The child is created lazily on first access and is wired to this as its parent.

Implementation

Resolvable<Lazy<DI>> registerChild({
  Entity groupEntity = const DefaultEntity(),
}) {
  final container = switch (childrenContainer) {
    Some(value: final c) => c,
    None() => () {
        final c = DI();
        childrenContainer = Some(c);
        return c;
      }(),
  };
  // `DI` instances are per-isolate by design (mutable registry, completers,
  // timers). This closure captures `this` intentionally to wire the child's
  // parent link; the resulting `Lazy<DI>` is never expected to cross isolate
  // boundaries.
  return container.registerLazy<DI>(
    // ignore: sendable
    () => Sync.okValue(DI()..parents.add(this as DI)),
    groupEntity: groupEntity,
  );
}