getDependency<T extends Object> method
Option<Result<Dependency<T> > >
getDependency<T extends Object>({
- Entity groupEntity = const DefaultEntity(),
- bool traverse = true,
- @Deprecated('Cycle detection is internal; this parameter is now ignored.') Set<
DI> ? visited,
Retrieves the underlying Dependency object from the registry.
Iterative DFS — see isRegistered.
Implementation
Option<Result<Dependency<T>>> getDependency<T extends Object>({
Entity groupEntity = const DefaultEntity(),
bool traverse = true,
@Deprecated('Cycle detection is internal; this parameter is now ignored.')
Set<DI>? visited,
}) {
final seen = <DI>{};
final stack = <(DI, Entity)>[
(this as DI, groupEntity.preferOverDefault(focusGroup)),
];
while (stack.isNotEmpty) {
final (di, g) = stack.removeLast();
if (!seen.add(di)) continue;
final option = di.registry.getDependency<T>(groupEntity: g);
if (option case Some()) {
return option.map((e) => Ok(e).transf<Dependency<T>>());
}
if (!traverse) break;
final parentList = di.parents.toList(growable: false);
for (var i = parentList.length - 1; i >= 0; i--) {
final parent = parentList[i];
stack.add((parent, g.preferOverDefault(parent.focusGroup)));
}
}
return const None();
}