beans library

The dependency-injection container: bean definitions, the bean factory that creates and wires the beans, scopes, lifecycle callbacks and the post-processor hooks, plus BeanWrapper and the compile-time introspection that data binding and SpEL read.

Import it when you use the container without an application context (a small tool, a test), or when you write library code that registers bean definitions or post-processes beans. An application normally does not import it on its own: it declares beans with annotations (@Component(), @Bean()), lets the generator write the definitions and starts an ApplicationContext, which owns a factory from this library. package:spring_core_dart/spring_core_dart.dart exports it.

// A container without a context: one bean registered by hand.
final factory = DefaultListableBeanFactory()
  ..registerBeanDefinition(
    BeanDefinition<Clock>(name: 'clock', create: (_) => SystemClock()),
  );
final clock = factory.getBean<Clock>();

Spring (Java): the spring-beans module.

var factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition("clock",
    new RootBeanDefinition(SystemClock.class));
Clock clock = factory.getBean(Clock.class);

Classes

AutowireCapableBeanFactory
The part of the container that injects and initializes objects it did not create.
Aware
The common supertype of the interfaces through which the container hands a bean one of its own objects: its bean name, the bean factory, the environment and so on.
BeanConstructor<T extends Object>
The description of the constructor an introspected class is created with (the unnamed one, or the one marked @JsonCreator()), with a closure that calls it.
BeanDefinition<T extends Object>
The recipe for one bean: its name, the types it can be found by, its scope and flags, and the closures that create, inject, initialize and destroy it.
BeanDefinitionRegistry
The write side of the container: where bean definitions are registered, removed and given aliases.
BeanDefinitionRegistryPostProcessor
A BeanFactoryPostProcessor that may also add, remove or replace bean definitions, before any postProcessBeanFactory runs.
BeanExpressionResolver
Evaluates the #{...} expressions of @Value strings, after their ${...} placeholders are resolved.
BeanFactory
The read side of the container: it hands out beans by type or by name and answers questions about them without creating them.
BeanFactoryAware
A bean that is handed the bean factory that created it, so it can look up other beans by itself while it runs.
BeanFactoryPostProcessor
A hook that runs once at startup, after all bean definitions are registered and before any ordinary bean is created, to inspect or change them.
BeanFactoryUtils
Helpers that list beans across a whole hierarchy of factories, and that handle the & prefix of factory bean names.
BeanIntrospection<T extends Object>
Everything the generator knows about an introspected class: its properties, methods, constructor and annotations, with closures to use them.
BeanIntrospector
The registry that finds the BeanIntrospection of a class or object.
BeanMethod<T extends Object>
The description of one public instance method of an introspected class or bean, with a closure that calls it.
BeanNameAware
A bean that is told the name it is registered under.
BeanParameter
The description of one parameter of a constructor or method: its name, full type, whether it is named or required, and its annotations.
BeanPostProcessor
A hook that sees every bean as it is created, and may change or replace it before the container hands it out.
BeanProperty<T extends Object>
The description of one property of an introspected class: its name, type, annotations, and closures that read and write it.
BeanWrapper
Reads and writes the properties of an object by path (address.city, tags[0]), converting written values to the property types.
ClassType<T>
The TypeInfo of a class or scalar type that needs no further description: ClassType<String>(), ClassType<Book>().
CommonAnnotationBeanPostProcessor
A marker in the post-processor chain that says where the @PostConstruct methods run.
ConfigurableBeanFactory
The settings side of a bean factory: parent, conversion, @Value resolution, bean post-processors, custom scopes, dependency records and shutdown.
ConfigurableListableBeanFactory
The container's full control: besides handing out beans, it lets code change bean definitions and the container's setup before any bean is created.
CustomScope
A place that keeps bean instances for a span of your choosing, such as a screen, a session or a job, and so defines a custom bean scope.
DefaultListableBeanFactory
The bean container itself: it holds the bean definitions, creates the beans in dependency order, injects them, and destroys them at the end.
Dependency
The description of one injection point of a bean, used to check the bean graph at startup before anything is created.
DependencyResolver
The view of the container that a bean definition's create and inject callbacks receive, to get the dependencies of the bean being built.
DestructionAwareBeanPostProcessor
A BeanPostProcessor that is also called before each bean is destroyed.
DisposableBean
A bean that wants a call when the container discards it, to release what it holds: connections, files, timers, subscriptions.
DynamicType
The TypeInfo of dynamic, Object? or a type that is not described further: values are taken as they are. void (e.g. of ResponseEntity<void>) is DynamicType.forVoid, so a reader can ignore the value.
EnumType<E extends Enum>
The TypeInfo of an enum, with its values, so a value can be found by name: EnumType<Mood>(Mood.values). jsonValue reads the field marked @JsonValue(), when the enum has one.
FactoryBean<T extends Object>
A bean whose job is to make another object: the container hands out what getObject returns, not the factory itself.
GenericType<T>
The TypeInfo of a generic class other than the collections, with the descriptions of its type arguments: GenericType<ResponseEntity<Book>>([ClassType<Book>()]). T is the whole type; arguments describe its type arguments in order.
HierarchicalBeanFactory
A bean factory with a parent: what it cannot find among its own beans, it looks up in the parent.
InitializingBean
A bean that wants a call once all its dependencies are injected, to finish its setup.
InstantiationAwareBeanPostProcessor
A BeanPostProcessor that is also called around the creation and the injection of each bean, not only around its initialization.
InterfaceMetadata<T extends Object>
The description of an interface that is implemented by a proxy: its name, its annotations and its methods.
InterfaceProxies
The lookup that generated proxy code uses to get its handler; not meant for other code.
InterfaceProxy
Marks an annotation class whose interfaces become beans implemented by generated code: each call is handed to an InvocationHandler.
Introspected
Marks a class whose properties, constructor and methods the generator describes, so the framework can read and fill its objects without reflection.
InvocationHandler
The object that does the work of an interface proxy: every call of the generated implementation ends up in invoke.
InvocationHandlerFactory
A bean that provides the InvocationHandler for the interface proxies it supports, for example those annotated @FeignClient.
ListableBeanFactory
A bean factory that can list its beans: all names, the beans of a type, the beans carrying an annotation.
ListType<E>
The TypeInfo of a List<E>, with the description of its elements: ListType<Book>(ClassType<Book>()).
MapType<K, V>
The TypeInfo of a Map<K, V>, with the descriptions of its keys and values: MapType<String, int>(ClassType<String>(), ClassType<int>()).
MergedBeanDefinitionPostProcessor
A BeanPostProcessor that is shown each bean definition once, when its first bean has been constructed and before it is injected.
NullBean
The object that stands for a bean whose @Bean method (or create callback) returned null.
ObjectFactory<T extends Object>
Something that returns an object of T when asked: the smallest form of a lazy dependency.
ObjectProvider<T extends Object>
A handle on the beans of T that looks them up only when asked: one bean, the bean if there is one, or all of them.
ProxyMethod
The description of one method of an interface proxy: its name, parameters, return type and annotations, and a way to call it.
ScopeType
The names of the two built-in scopes, for @Scope(...) and BeanDefinition.scope.
SetType<E>
The TypeInfo of a Set<E>, with the description of its elements: SetType<String>(ClassType<String>()).
SimpleMapScope
A ready-made CustomScope that keeps its instances in a map until you call destroy.
SingletonBeanRegistry
The part of the container that accepts ready-made objects as beans.
SmartFactoryBean<T extends Object>
A FactoryBean that tells the container more about its product: whether it is a prototype, whether to create it at startup, and which other types it can serve.
SmartInitializingSingleton
A singleton that wants a call once every non-lazy singleton has been created, at the end of startup.
SmartInstantiationAwareBeanPostProcessor
An InstantiationAwareBeanPostProcessor that can also tell the type a bean will have before it is created.
TypeInfo<T>
A description of a full Dart type, such as List<Book> or String?, that code can take apart at run time without reflection.
TypeInfoVisitor<R>
One method per kind of TypeInfo, called by TypeInfo.accept with the kind's type arguments in scope.

Enums

DependencyKind
The form of an injection point that a Dependency describes: one bean, all beans of a type, a provider, a @Value, and so on.
IntrospectionPart
A part of an introspected class that a BeanIntrospection may leave out.
ScopedProxyMode
Whether a bean of a custom (or prototype) scope is injected directly or through a scoped proxy (@Scope(proxyMode:)).

Typedefs

BeanConfigurer = void Function(Object bean, DependencyResolver resolver)
A function that injects the dependencies of an object the container did not create, an instance of a @Configurable class.
StringValueResolver = String Function(String value)
A function that resolves the ${...} placeholders in a string and returns the result.

Exceptions / Errors

BeanCreationException
The error thrown when creating a bean failed: its constructor or @Bean method, its injection or an init callback threw.
BeanCreationNotAllowedException
The error thrown when a singleton that does not exist yet is requested while the factory destroys its singletons.
BeanCurrentlyInCreationException
The error thrown when beans depend on each other in a cycle, so none of them can be created first.
BeanDefinitionOverrideException
The error thrown when a bean name or alias is registered while the name is already taken.
BeanDefinitionStoreException
The error thrown when a bean definition cannot be registered: an invalid name, or a name that is taken.
BeanIsNotAFactoryException
The error thrown when &name asks for the factory of a bean that is not a FactoryBean.
BeanNotOfRequiredTypeException
The error thrown when a bean exists but is not of the requested type.
BeansException
The common supertype of the errors the container throws: a missing or ambiguous bean, a failed creation, a clashing name, a bad property path.
IntrospectionPartError
The error thrown when code needs a part of an introspected class that its description leaves out.
InvalidPropertyException
The error a BeanWrapper throws when a property path is malformed (items[, address..city).
MethodInvocationException
The error a BeanWrapper throws when a property's setter itself threw, for example because it validates the value.
NoSuchBeanDefinitionException
The error thrown when no bean matches a requested type, qualifier or name.
NotReadablePropertyException
The error a BeanWrapper throws when a property path cannot be read.
NotWritablePropertyException
The error a BeanWrapper throws when a property path cannot be written.
NoUniqueBeanDefinitionException
The error thrown when several beans match a requested type and none of them wins.
NullValueInNestedPathException
The error a BeanWrapper throws when a path goes through a null value, such as address in address.city.
PropertyBatchUpdateException
The error BeanWrapper.setPropertyValues throws when one or more of the values could not be written, after trying all of them.
ScopeNotActiveException
The error thrown when a bean is looked up while its scope is not active, for example a screen-scoped bean while no screen is open.
ScopeNotRegisteredException
The error thrown when a bean of a custom scope is looked up and no scope of that name is registered.
TypeMismatchException
The error a BeanWrapper throws when a value cannot be converted to the type of the property it is written to, such as 'old' for an int.
UnsatisfiedDependencyException
The error thrown when an injection point of a bean cannot be filled: the bean, its injection point and the reason are in the message.