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
registerSingletonare not counted).no setterinherited -
beanDefinitionNames
→ List<
String> -
The names of the definitions registered here, in registration order.
Objects added with
registerSingletonare not definitions and are not listed.no setterinherited - beanExpressionResolver ↔ BeanExpressionResolver?
-
Evaluates the
#{...}part of@Valuestrings.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
@Valueexpression to the injection point's type (the string'8080'to anint, say). Defaults to the sharedDefaultConversionService; 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
destroyBeanand 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;
nullfor a root factory.getter/setter pairinherited -
registeredScopeNames
→ List<
String> -
The names of the custom scopes registered so far (not
singletonorprototype).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
processorto 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
resolverto the chain run over every@Valuestring 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
@Autowiredand@Valuemembers ofexistingBean. Its exact runtime class must be@Configurableand its module registered; otherwise throwsArgumentError. Init callbacks do not run: call initializeBean for those.inherited -
containsBean(
String name) → bool -
Whether a bean or alias named
nameexists here or in a parent (&nameonly 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 withregisterSingletondo not count.inherited -
containsBeanOfType(
Type type, {String? qualifier, bool includeAncestors = true}) → bool -
Whether injecting
typewould 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(&nameonly 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
Tfor a required injection point.qualifieris the@Qualifiervalue;nameis 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 aList<T>point, sorted:PriorityOrderedfirst, then byOrdered.order,@Orderor@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
Tby bean name, for aMap<String, T>point, in registration order (this factory's beans first). Like in Spring, only lists are sorted; aSet<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@PreDestroymethods of a@Configurableclass andDisposableBean.destroy. WithbeanName, 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 indestructionErrors.inherited -
destroyScopedBean(
String name) → void -
Removes the current instance of the bean
namefrom 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. ThrowsArgumentErrorwhen the bean is not in a custom scope andNoSuchBeanDefinitionExceptionwhen 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
registerSingletonare kept and not destroyed. An application context calls it onclose().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'scloseAsync()calls this.inherited -
findAnnotationOnBean<
A extends Object> (String beanName) → A? -
The first annotation of type
Aon the class (or@Beanmethod) of the bean namedbeanName, ornull. Creates no bean. Looks in the parent when the bean is not known here, and throwsNoSuchBeanDefinitionExceptionwhen no factory has it. Spring:findAnnotationOnBean.inherited -
findBean<
T extends Object> ({String? qualifier}) → T? -
Like getBean, but returns
nullwhen no bean matches, for a collaborator the caller can do without. Still throwsNoUniqueBeanDefinitionExceptionwhen 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 whennameis 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. Withqualifier, only the bean with that name, alias or@Qualifiervalue.inherited -
getBeanByName(
String name) → Object -
The bean registered under
nameor 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. ThrowsNoSuchBeanDefinitionExceptionwhen unknown.inherited -
getBeanNamesForAnnotation<
A extends Object> () → List< String> -
The names of this factory's definitions whose class (for a
@Beanmethod: the method or the returned class) carries an annotation of typeAor of a subclass ofA, so asking forComponentalso finds@Servicebeans. 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 withregisterSingleton. Creates no bean.inherited -
getBeanProvider<
T extends Object> ({String? qualifier}) → ObjectProvider< T> -
A handle on the beans of
Tthat creates nothing until it is used.inherited -
getBeansOfType<
T extends Object> ({bool includeNonSingletons = true}) → Map< String, T> -
This factory's beans of
Tby name, in the order of getBeanNamesForType; creates those that do not exist yet. A bean whose@Beanmethod returnednullis 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
beanNameis 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, ornull(also forsingletonandprototype).inherited -
getSingleton(
String name) → Object? -
The singleton named
name(or an alias) if it has been created or registered, elsenull; 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
There and in the parent factories, sorted to be used in order:PriorityOrderedbeans first, then byOrdered.order,@Orderor 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 aSmartInstantiationAwareBeanPostProcessorpredicts), the product type for a factory bean (&name: the factory's class), the runtime type of an object added withregisterSingleton.nullwhen no bean has that name.inherited -
initializeBean(
Object existingBean, String beanName) → Object -
Runs on
existingBeanwhat the container runs on its own beans after injection: the aware callbacks, the post-processors, the@PostConstructmethods of a@Configurableclass andInitializingBean.afterPropertiesSet.beanNameis 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
beanNameis 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
nameis aFactoryBean(here or in a parent), without creating it. ThrowsNoSuchBeanDefinitionExceptionwhen no bean has that name. Spring:isFactoryBean(String).inherited -
isPrototype(
String name) → bool -
Whether every lookup of the bean named
namecreates a new instance. For aFactoryBean, whether its product is created per lookup (this creates the factory);&nameasks about the factory itself. A bean in a custom scope is neither a singleton nor a prototype. ThrowsNoSuchBeanDefinitionExceptionfor an unknown name.inherited -
isSingleton(
String name) → bool -
Whether the bean named
nameis one shared instance. For aFactoryBean, whether its product is shared (this creates the factory);&nameasks about the factory itself. ThrowsNoSuchBeanDefinitionExceptionfor an unknown name.inherited -
isTypeMatch(
String name, Type type) → bool -
Whether the bean named
namecan be used as atype, 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
Teach time it is called, as if it were injected into the bean being created now. The generated proxy of a@Lazyinjection 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:
nullwhen 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
nullwhen there is none. -
optionalDependencyMap<
T extends Object> ({String? qualifier}) → Map< String, T> ? -
Like dependencyMap, but
nullwhen there is none. -
optionalResource<
T extends Object> (String name, {bool fallbackToType = false}) → T? -
Like resource, for a nullable point:
nullwhen the bean is missing. -
optionalValue<
T> (String expression) → T? -
Like value, for a nullable point:
nullwhen 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.afterSingletonsInstantiatedon the beans that implement it. The product of aSmartFactoryBeanwhoseisEagerInitistrueis created too.inherited -
preInstantiateSingletonsAsync(
) → Future< void> -
Like preInstantiateSingletons, but awaits the init callbacks that
returned a
Future(in creation order; a failure is aBeanCreationExceptionof that bean) beforeSmartInitializingSingleton.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 ifTwere injected into the bean being created now (nameis the parameter or field name). Used for optional, late or multiple beans, and to break a cycle. -
registerAlias(
String name, String alias) → void -
Makes
aliasa second name of the beanname: lookups by name,@Qualifiervalues and parameter names match it. ThrowsBeanDefinitionOverrideExceptionwhenaliasis 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
dependentBeanNameuses the beanbeanName, 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
valueinjectable wherever exactlytypeis asked for, without making it a bean: it has no name, is not listed, and is used only when no bean oftypematches 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
scopeundername, so beans declared with@Scope(name)get their instances from it.inherited -
registerSingleton(
String name, Object singleton, {List< Type> ? types}) → void -
Registers
singletonundername. It is found by that name and by thetypeslisted, 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 (valueitself 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
@Resourcefield or setter (frompackage:spring_core_dart/jakarta.dart): the bean namedname(an alias or&factorytoo), asT. -
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
@ValueexpressionasT: the${...}placeholders are resolved, then#{...}is evaluated, then the result is converted toT(aResourcecomes 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