getChild method

Option<Result<DI>> getChild({
  1. Entity groupEntity = const DefaultEntity(),
})
inherited

Returns the child registered under groupEntity wrapped in a Result, or None if no child is registered. The Result carries an Err if child construction failed.

Implementation

Option<Result<DI>> getChild({Entity groupEntity = const DefaultEntity()}) {
  final g = groupEntity.preferOverDefault(focusGroup);
  if (childrenContainer case Some(value: final container)) {
    // Collapse Option<Resolvable<DI>> → Option<Result<DI>>. Sync-Ok and
    // Sync-Err are direct; Async returns Err (caller can re-await
    // explicitly if they need the future shape).
    return switch (container.getLazySingleton<DI>(groupEntity: g)) {
      None() => const None(),
      Some(value: Sync(value: final result)) => Some(result),
      Some(value: Async()) =>
        Some(Err('getChild: lazy singleton resolved async, not supported.')),
    };
  }
  return const None();
}