MultiToken<T> class
A token representing multiple values of T
for dependency injection.
const usPresidents = const MultiToken<String>('usPresidents');
@Component(
selector: 'presidents-list',
providers: const [
const ValueProvider.forToken(usPresidents, 'George Washington'),
const ValueProvider.forToken(usPresidents, 'Abraham Lincoln'),
],
)
class PresidentsListComponent {
// Will be ['George Washington', 'Abraham Lincoln'].
final List<String> items;
PresidentsListComponent(@Inject(usPresidents) this.items);
}
The type T
is not required, but is recommended, otherwise it is dynamic
.
The only positional argument, uniqueName
, is used to determine uniqueness
of the token. That is, const MultiToken('SECRETS')
is identical to
const MultiToken('SECRETS')
in another library or package.
You may also sub-class MultiToken to create a "more unique" token:
class UsPresidents extends MultiToken<String> {
const UsPresidents();
}
const usPresidents = const UsPresidents();
@Component(
selector: 'presidents-list',
providers: const [
const ValueProvider.forToken(usPresidents, 'George Washington'),
const ValueProvider.forToken(usPresidents, 'Abraham Lincoln'),
],
)
class PresidentsListComponent {
// Will be ['George Washington', 'Abraham Lincoln'].
final List<String> items;
PresidentsListComponent(@Inject(usPresidents) this.items);
}
This is is the preferred mechanism for configuring multiple bound values to
a single token, and will replace Provider(..., multi: true)
and other
variations of the multi: true
APIs.
WARNING: It is not supported to create a non-const instance of this
class or sub-types of this class. Instances should only be created or
referenced using the const
operator.
- Inheritance
- Object
- OpaqueToken<
List< T> > - MultiToken
- Annotations
Constructors
- MultiToken([String uniqueName = ''])
-
const
Properties
- hashCode → int
-
The hash code for this object. [...]
read-only, inherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
-
toString(
) → String -
Returns a string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator. [...]
inherited