child method

DI child({
  1. Entity groupEntity = const DefaultEntity(),
})
inherited

Returns the child container under groupEntity, registering one lazily if needed. This is the convenience entry point most callers reach for — DI.global, DI.session, DI.user, etc. all funnel through here.

Implementation

DI child({Entity groupEntity = const DefaultEntity()}) {
  if (!isChildRegistered(groupEntity: groupEntity)) {
    registerChild(groupEntity: groupEntity).end();
  }
  return switch (getChild(groupEntity: groupEntity)) {
    Some(value: Ok(value: final di)) => di,
    Some(value: Err(:final error)) =>
      throw StateError('child(): construction failed: $error'),
    None() => throw StateError(
        'child(): registerChild succeeded but getChild returned None.',
      ),
  };
}