require<T> method
Require a dependency — throws ZenDependencyNotFoundException with a helpful message if the type is not registered in this scope hierarchy.
Prefer this over find<T>()! (null-assertion) in production code.
The thrown exception includes the type name, scope name, optional tag,
and a ready-to-paste registration suggestion.
// ❌ Avoid — crashes with null-dereference, no context
final svc = scope.find<MyService>()!;
// ✅ Prefer — throws ZenDependencyNotFoundException with actionable message
final svc = scope.require<MyService>();
Implementation
T require<T>({String? tag}) {
final result = find<T>(tag: tag);
if (result == null) {
throw ZenDependencyNotFoundException(
typeName: T.toString(),
scopeName: name ?? 'UnnamedScope',
tag: tag,
);
}
return result;
}