The part of the container that injects and initializes objects it did not create.
Some objects are built by someone else: Flutter creates State
objects, a plugin system creates its handlers. When such an object
needs beans, mark its class @Configurable() (the generator then
writes its injection code) and hand the object to autowireBean.
Objects the container creates itself never need this.
// Flutter made this State; the container fills in its service.
@Configurable()
class ProfileScreenState extends State<ProfileScreen> {
@Autowired()
late final ProfileService profiles;
@override
void initState() {
super.initState();
appContext.autowireCapableBeanFactory.autowireBean(this);
}
}
Spring (Java):
context.getAutowireCapableBeanFactory().autowireBean(existingObject);
Unlike Spring, only @Configurable classes can be autowired (their
injection code is generated).
- Implemented types
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
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. -
containsBean(
String name) → bool -
Whether a bean or alias named
nameexists here or in a parent (&nameonly for a factory bean). Creates nothing.inherited -
containsBeanOfType(
Type type, {String? qualifier, bool includeAncestors = true}) → bool -
Whether injecting
typewould find a bean, without creating any.inherited -
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. -
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 -
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 -
getBeanProvider<
T extends Object> ({String? qualifier}) → ObjectProvider< T> -
A handle on the beans of
Tthat creates nothing until it is used.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. -
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 -
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