DependencyResolver class abstract interface

The view of the container that a bean definition's create and inject callbacks receive, to get the dependencies of the bean being built.

The generator writes these calls for every injection point, so most code never calls them. You write them yourself in hand-made bean definitions, such as create: (r) => LowStockAlarm(r.dependency<StockService>()). Lookups made through it are recorded (the bean is destroyed before its dependencies), and a failure while the bean is being created is thrown as an UnsatisfiedDependencyException naming the bean and the injection point.

Injection points are resolved like Spring's resolveDependency: the candidates are the autowire candidates of this factory and its parents (a parent bean is hidden by a local bean with the same name); without a qualifier only default candidates count. The bean being created and the beans of its own @Bean methods are left out (for a single bean only when nothing else matches), so a @Primary decorator of Greeter receives the other greeters. Among several candidates the winner is the single @Primary one (a local one beats a parent's; two at the same level are ambiguous), else the only non-@Fallback one, else the one whose name or alias equals the parameter name, then the one named by the @Qualifier value, then the one with the lowest jakarta @Priority, else the only default candidate.

// A hand-written definition for OrderService and its four
// dependencies.
BeanDefinition<OrderService>(
  name: 'orderService',
  create: (r) => OrderService(
    r.dependency<OrderRepository>(name: 'repository'),
    r.dependencyList<OrderListener>(),
    r.optionalDependency<Clock>(),
    r.value<int>(r'${orders.limit:100}'),
  ),
);

Spring (Java): no public counterpart; the equivalent work is done by reflection in AutowiredAnnotationBeanPostProcessor and DefaultListableBeanFactory.resolveDependency(...):

@Service
class OrderService {
  OrderService(OrderRepository repository, List<OrderListener> listeners,
      Optional<Clock> clock, @Value("${orders.limit:100}") int limit) {}
}
Implemented types

Properties

beanDefinitionCount → int
How many definitions are registered here (objects added with registerSingleton are not counted).
no setterinherited
beanDefinitionNames → List<String>
The names of the definitions registered here, in registration order. Objects added with registerSingleton are not definitions and are not listed.
no setterinherited
beanExpressionResolver ↔ BeanExpressionResolver?
Evaluates the #{...} part of @Value strings. null, the default of a bare factory, leaves them as written; an application context sets the SpEL resolver.
getter/setter pairinherited
beanPostProcessorCount → int
How many bean post-processors are registered.
no setterinherited
conversionService ↔ ConversionService
Converts the result of a @Value expression to the injection point's type (the string '8080' to an int, say). Defaults to the shared DefaultConversionService; an application context uses its environment's.
getter/setter pairinherited
destructionErrors → List<Object>
The errors thrown by destroy callbacks during the last destroySingletons or destroySingletonsAsync, and by destroyBean and destroyScopedBean since. Each was also logged as a warning; none stopped the shutdown.
no setterinherited
hasEmbeddedValueResolver → bool
Whether any placeholder resolver was added; without one, ${...} stays as written.
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
isConfigurationFrozen → bool
Whether freezeConfiguration has been called.
no setterinherited
parentBeanFactory ↔ BeanFactory?
The factory consulted when a lookup finds nothing here; null for a root factory.
getter/setter pairinherited
registeredScopeNames → List<String>
The names of the custom scopes registered so far (not singleton or prototype).
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
singletonNames → List<String>
The names of the singletons that exist so far, created or registered.
no setterinherited

Methods

addBeanPostProcessor(BeanPostProcessor processor) → void
Adds processor to the chain applied to every bean created from now on, after the ones already added; adding one again moves it to the end. Beans that exist already are not processed. An application context adds the post-processor beans itself; call this on a bare factory, or for a processor that is not a bean.
inherited
addEmbeddedValueResolver(StringValueResolver resolver) → void
Adds resolver to the chain run over every @Value string to resolve its ${...} placeholders. Resolvers run in the order added, each on the previous one's result. An application context adds the environment's.
inherited
autowireBean(Object existingBean) → void
Injects the @Autowired and @Value members of existingBean. Its exact runtime class must be @Configurable and its module registered; otherwise throws ArgumentError. Init callbacks do not run: call initializeBean for those.
inherited
containsBean(String name) → bool
Whether a bean or alias named name exists here or in a parent (&name only for a factory bean). Creates nothing.
inherited
containsBeanDefinition(String name) → bool
Whether a definition is registered here under exactly name. Aliases, parent beans and objects added with registerSingleton do not count.
inherited
containsBeanOfType(Type type, {String? qualifier, bool includeAncestors = true}) → bool
Whether injecting type would find a bean, without creating any.
inherited
containsLocalBean(String name) → bool
Whether this factory itself, ignoring the parent, has a bean or alias named name (&name only for a factory bean).
inherited
containsSingleton(String name) → bool
Whether the singleton named name (or an alias) exists already, created or registered.
inherited
dependency<T extends Object>({String? qualifier, String? name}) → T
The bean of T for a required injection point. qualifier is the @Qualifier value; name is the parameter or field name, which picks the candidate whose name or alias equals it when several remain (like Spring). Throws when no bean, or no single winner, is found.
dependencyList<T extends Object>({String? qualifier}) → List<T>
Every matching bean of T, for a List<T> point, sorted: PriorityOrdered first, then by Ordered.order, @Order or @Priority, then registration order. Includes the parents' beans. Throws when there is none.
dependencyMap<T extends Object>({String? qualifier}) → Map<String, T>
Every matching bean of T by bean name, for a Map<String, T> point, in registration order (this factory's beans first). Like in Spring, only lists are sorted; a Set<T> point is built from these values. Throws when there is none.
destroyBean(Object existingBean, {String? beanName}) → void
Runs the destroy callbacks of existingBean: destruction-aware post-processors, the @PreDestroy methods of a @Configurable class and DisposableBean.destroy. With beanName, the destroy callbacks of that bean definition run instead, for example to release a prototype instance, which the container never destroys by itself. Errors are logged and collected in destructionErrors.
inherited
destroyScopedBean(String name) → void
Removes the current instance of the bean name from its custom scope and runs its destroy callbacks, for example when one screen closes while its scope goes on. Does nothing when the scope holds no instance. Throws ArgumentError when the bean is not in a custom scope and NoSuchBeanDefinitionException when no bean has that name.
inherited
destroySingletons() → void
Destroys every singleton the factory created, in reverse creation order and each after the beans that depend on it, then forgets them. Objects added with registerSingleton are kept and not destroyed. An application context calls it on close().
inherited
destroySingletonsAsync() → Future<void>
Like destroySingletons, but awaits the destroy callbacks that return a Future (@PreDestroy, DisposableBean.destroy, the destroy method): each bean's callbacks one after another, each bean after its dependents. The application context's closeAsync() calls this.
inherited
findAnnotationOnBean<A extends Object>(String beanName) → A?
The first annotation of type A on the class (or @Bean method) of the bean named beanName, or null. Creates no bean. Looks in the parent when the bean is not known here, and throws NoSuchBeanDefinitionException when no factory has it. Spring: findAnnotationOnBean.
inherited
findBean<T extends Object>({String? qualifier}) → T?
Like getBean, but returns null when no bean matches, for a collaborator the caller can do without. Still throws NoUniqueBeanDefinitionException when several match and none wins. Spring: getBeanProvider(T).getIfAvailable().
inherited
freezeConfiguration() → void
Declares that the definitions will not change any more, so the factory may cache which bean each lookup and injection point selects. The application context calls it before creating the singletons. Like in Spring it is only a hint: registering or removing definitions afterwards still works and clears the caches.
inherited
getAliases(String name) → List<String>
The other names of the bean named name: its aliases, plus its bean name when name is itself an alias. Empty when there are none or no bean has that name.
inherited
getBean<T extends Object>({String? qualifier}) → T
The bean of type T, created if it does not exist yet. With qualifier, only the bean with that name, alias or @Qualifier value.
inherited
getBeanByName(String name) → Object
The bean registered under name or one of its aliases, created if needed; looks in the parent when the name is not known here.
inherited
getBeanDefinition(String name) → BeanDefinition<Object>
The definition registered as name (or an alias, or &name), to read or change. Its mutable fields (scope, lazy, primary, fallback, autowireCandidate, ...) apply to beans created afterwards. Throws NoSuchBeanDefinitionException when unknown.
inherited
getBeanNamesForAnnotation<A extends Object>() → List<String>
The names of this factory's definitions whose class (for a @Bean method: the method or the returned class) carries an annotation of type A or of a subclass of A, so asking for Component also finds @Service beans. Creates no bean. Spring: getBeanNamesForAnnotation.
inherited
getBeanNamesForType(Type type, {bool includeNonSingletons = true}) → List<String>
The names of this factory's beans that can be used as type, in registration order: definitions first, then objects added with registerSingleton. Creates no bean.
inherited
getBeanProvider<T extends Object>({String? qualifier}) → ObjectProvider<T>
A handle on the beans of T that creates nothing until it is used.
inherited
getBeansOfType<T extends Object>({bool includeNonSingletons = true}) → Map<String, T>
This factory's beans of T by name, in the order of getBeanNamesForType; creates those that do not exist yet. A bean whose @Bean method returned null is left out.
inherited
getBeansWithAnnotation<A extends Object>() → Map<String, Object>
The beans named by getBeanNamesForAnnotation, by name; creates them. Spring: getBeansWithAnnotation.
inherited
getDependenciesForBean(String beanName) → List<String>
The names of the beans beanName is recorded as using.
inherited
getDependentBeans(String beanName) → List<String>
The names of the beans recorded as using beanName; they are destroyed before it.
inherited
getRegisteredScope(String name) → CustomScope?
The custom scope registered under name, or null (also for singleton and prototype).
inherited
getSingleton(String name) → Object?
The singleton named name (or an alias) if it has been created or registered, else null; never creates it. For a factory bean this is the factory, not its product.
inherited
getSortedBeans<T extends Object>({String? qualifier}) → List<T>
Every bean of T here and in the parent factories, sorted to be used in order: PriorityOrdered beans first, then by Ordered.order, @Order or jakarta @Priority (lower first), then by registration.
inherited
getType(String name) → Type?
The type of the bean named name, without creating it: the declared class (or what a SmartInstantiationAwareBeanPostProcessor predicts), the product type for a factory bean (&name: the factory's class), the runtime type of an object added with registerSingleton. null when no bean has that name.
inherited
initializeBean(Object existingBean, String beanName) → Object
Runs on existingBean what the container runs on its own beans after injection: the aware callbacks, the post-processors, the @PostConstruct methods of a @Configurable class and InitializingBean.afterPropertiesSet. beanName is the name those callbacks receive. Returns the object to use from now on, which a post-processor may have wrapped.
inherited
isCurrentlyInCreation(String beanName) → bool
Whether beanName is being created right now: its creation has started and not finished. A post-processor can check it to avoid asking for a bean that is still being built.
inherited
isFactoryBean(String name) → bool
Whether the bean named name is a FactoryBean (here or in a parent), without creating it. Throws NoSuchBeanDefinitionException when no bean has that name. Spring: isFactoryBean(String).
inherited
isPrototype(String name) → bool
Whether every lookup of the bean named name creates a new instance. For a FactoryBean, whether its product is created per lookup (this creates the factory); &name asks about the factory itself. A bean in a custom scope is neither a singleton nor a prototype. Throws NoSuchBeanDefinitionException for an unknown name.
inherited
isSingleton(String name) → bool
Whether the bean named name is one shared instance. For a FactoryBean, whether its product is shared (this creates the factory); &name asks about the factory itself. Throws NoSuchBeanDefinitionException for an unknown name.
inherited
isTypeMatch(String name, Type type) → bool
Whether the bean named name can be used as a type, judged from the types its definition declares, without creating it.
inherited
lazyDependency<T extends Object>({String? qualifier, String? name}) → T Function()
A function that resolves the bean of T each time it is called, as if it were injected into the bean being created now. The generated proxy of a @Lazy injection point calls it on every member access, so the bean is found on first use and a cycle is broken.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
optionalDependency<T extends Object>({String? qualifier, String? name}) → T?
Like dependency, for a nullable point: null when no bean matches (or the match is a null bean). Several candidates without a winner still throw.
optionalDependencyList<T extends Object>({String? qualifier}) → List<T>?
Like dependencyList, but null when there is none.
optionalDependencyMap<T extends Object>({String? qualifier}) → Map<String, T>?
Like dependencyMap, but null when there is none.
optionalResource<T extends Object>(String name, {bool fallbackToType = false}) → T?
Like resource, for a nullable point: null when the bean is missing.
optionalValue<T>(String expression) → T?
Like value, for a nullable point: null when a placeholder has no value.
preInstantiateSingletons() → void
Creates every singleton that is not lazy, so failures show at startup rather than on first use, then calls SmartInitializingSingleton.afterSingletonsInstantiated on the beans that implement it. The product of a SmartFactoryBean whose isEagerInit is true is created too.
inherited
preInstantiateSingletonsAsync() → Future<void>
Like preInstantiateSingletons, but awaits the init callbacks that returned a Future (in creation order; a failure is a BeanCreationException of that bean) before SmartInitializingSingleton.afterSingletonsInstantiated. Only beans created up to this point may have asynchronous init callbacks: for a bean created later (lazy, prototype, scoped) they fail its creation.
inherited
provider<T extends Object>({String? qualifier, String? name}) → ObjectProvider<T>
An ObjectProvider<T> for a provider injection point. Nothing is resolved now: each later call resolves as if T were injected into the bean being created now (name is the parameter or field name). Used for optional, late or multiple beans, and to break a cycle.
registerAlias(String name, String alias) → void
Makes alias a second name of the bean name: lookups by name, @Qualifier values and parameter names match it. Throws BeanDefinitionOverrideException when alias is already a bean name, or an alias of another bean while overriding is not allowed. Spring: ConfigurableBeanFactory.registerAlias.
inherited
registerDependentBean(String beanName, String dependentBeanName) → void
Records that the bean dependentBeanName uses the bean beanName, so it is destroyed before it. The container records this itself for every injection and @DependsOn; call it for a dependency it cannot see, such as a bean looked up by name inside a method.
inherited
registerResolvableDependency(Type type, Object value) → void
Makes value injectable wherever exactly type is asked for, without making it a bean: it has no name, is not listed, and is used only when no bean of type matches and the point has no qualifier. The application context registers its bean factory and itself this way, so they can be injected. Spring: registerResolvableDependency.
inherited
registerScope(String name, CustomScope scope) → void
Registers scope under name, so beans declared with @Scope(name) get their instances from it.
inherited
registerSingleton(String name, Object singleton, {List<Type>? types}) → void
Registers singleton under name. It is found by that name and by the types listed, which default to its runtime type only, so list every type it should be injected as.
inherited
resolveEmbeddedValue(String value) → String
Runs every added resolver over value, in order, and returns the result (value itself when there is none). Throws what a resolver throws, e.g. for a placeholder that has no value.
inherited
resource<T extends Object>(String name, {bool fallbackToType = false}) → T
The bean for a @Resource field or setter (from package:spring_core_dart/jakarta.dart): the bean named name (an alias or &factory too), as T.
toString() → String
A string representation of this object.
inherited
validateBeanGraph() → void
Checks the whole bean graph without creating any bean, so a configuration error fails at startup instead of on first use.
inherited
value<T>(String expression) → T
The value of a @Value expression as T: the ${...} placeholders are resolved, then #{...} is evaluated, then the result is converted to T (a Resource comes from the context's resource loader). Throws when a placeholder has neither a value nor a default.

Operators

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