Dependency class final

The description of one injection point of a bean, used to check the bean graph at startup before anything is created.

A definition's create and inject callbacks are closures: the container cannot see which beans they will ask for. So generated definitions also list one Dependency per injection point, and validateBeanGraph uses that list to report missing, ambiguous and circular dependencies before any constructor runs. Hand-written definitions may leave it out; validation then skips those edges and a problem shows only when the bean is created.

// A hand-written definition that declares what `create` will ask for.
BeanDefinition<Checkout>(
  name: 'checkout',
  dependencies: const [
    Dependency(Payments, name: 'payments'),
    Dependency.collection(Validator),
    Dependency.provider(Audit),
    Dependency.value(r'${shop.currency:EUR}'),
  ],
  create: (r) => Checkout(
    r.dependency<Payments>(name: 'payments'),
    r.dependencyList<Validator>(),
    r.provider<Audit>(),
    r.value<String>(r'${shop.currency:EUR}'),
  ),
);

Spring (Java): no direct counterpart. Spring finds injection points by reflection at creation time (DependencyDescriptor, InjectionPoint); it does not validate the whole graph up front.

Constructors

Dependency(Type type, {String? qualifier, String? name, bool optional = false})
One bean of type. qualifier is the @Qualifier value, name the parameter or field name (it picks among several candidates), and optional marks a nullable point.
const
Dependency.collection(Type type, {String? qualifier, bool optional = false})
All beans of type, for a List or Set point; with optional (a nullable point) having none is fine.
const
Dependency.lazy(Type type, {String? qualifier, String? name})
A @Lazy point of type: checked at startup like a single bean, but resolved on first use, so it never closes a cycle.
const
Dependency.map(Type type, {String? qualifier, bool optional = false})
All beans of type by bean name, for a Map<String, T> point.
const
Dependency.provider(Type type, {String? qualifier, String? name})
A lazy provider of type; name (the parameter or field name) selects among several candidates like for a single bean.
const
Dependency.resource(Type type, String name, {bool fallbackToType = false, bool optional = false})
A @Resource field or setter of type: the bean named name; with fallbackToType (the name was not given explicitly) a bean of type when no bean has that name.
const
Dependency.value(String expression, {bool optional = false})
A @Value expression; with optional (a nullable point) a placeholder without a value is fine.
const

Properties

expression → String?
The @Value expression for DependencyKind.value.
final
fallbackToType → bool
Whether a DependencyKind.resource falls back to injection by type when no bean is named name.
final
hashCode → int
The hash code for this object.
no setterinherited
kind → DependencyKind
The form of the injection point.
final
name → String?
The parameter or field name. When several beans match, the one with this name or alias is chosen.
final
optional → bool
Whether the point accepts a missing bean (or a placeholder without a value).
final
qualifier → String?
The bean name, alias or @Qualifier value the point requires, if any.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
type → Type
The requested type; for collections and maps, the element type.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited