HierarchicalBeanFactory class abstract interface

A bean factory with a parent: what it cannot find among its own beans, it looks up in the parent.

A parent lets separate parts of a program share common beans (a database, a clock) while each part keeps beans of its own: the child sees the parent's beans, the parent does not see the child's. Most applications have a single context and never set a parent.

// A feature module gets its own factory on top of the shared one.
final shared = DefaultListableBeanFactory();
final feature = DefaultListableBeanFactory(parentBeanFactory: shared);
feature.containsBean('clock');      // true if the shared factory has it
feature.containsLocalBean('clock'); // false

Spring (Java):

DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
child.containsBean("fromParent");
child.containsLocalBean("fromParent");
Implemented types

Properties

hashCode → int
The hash code for this object.
no setterinherited
parentBeanFactory → BeanFactory?
The factory consulted when a lookup finds nothing here; null for a root factory.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

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
containsLocalBean(String name) → bool
Whether this factory itself, ignoring the parent, has a bean or alias named name (&name only for a factory bean).
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
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