CobaltChildScope class
Declares a scope shorter than the app, whose builder the generator writes.
The annotated class is a marker, never instantiated by the generated code.
Its name, with Scope appended, names the builder: Session gives
SessionScope. Its constructor says what the scope is opened with, and
each parameter is registered in it as a value:
@CobaltChildScope()
class Session {
const Session(this.user);
final SessionUser user;
}
@CobaltInject(scope: Session)
class SessionActivityLog {
SessionActivityLog(this.user, this.events);
final SessionUser user;
final EventLog events;
}
final session = await app.open('session', SessionScope(user));
SessionScope registers user and every class annotated with
scope: Session. The build checks that each of them gets what it injects
from this scope or the ones above it, and that nothing above injects what
only this scope registers.
Every constructor parameter has to be an initializing formal
(this.user), and required: the generated builder repeats the
constructor, and a default value would not travel with it. @Named on the
parameter registers the value under that name.
- Annotations
-
- @Target.new({TargetKind.classType})
Constructors
-
CobaltChildScope({Type? parent, List<
Object> provides = const []}) -
Creates an annotation declaring a child scope.
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- parent → Type?
-
The child scope this one opens under, or null for the root.
final
-
provides
→ List<
Object> -
Registrations made in this scope by hand, which registrations here may
depend on. As for
CobaltScopeRoot.provides, an element is aTypeor a CobaltProvided.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited