AutowireCapableBeanFactory class abstract interface

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 @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.
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
containsBeanOfType(Type type, {String? qualifier, bool includeAncestors = true}) → bool
Whether injecting type would find a bean, without creating any.
inherited
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.
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
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
getBeanProvider<T extends Object>({String? qualifier}) → ObjectProvider<T>
A handle on the beans of T that 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 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.
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
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