InstantiationAwareBeanPostProcessor class abstract

A BeanPostProcessor that is also called around the creation and the injection of each bean, not only around its initialization.

It is for framework code that must supply a bean instead of the container (a stub in tests, a remote proxy), skip or add injection. Applications almost never need it.

postProcessBeforeInstantiation may return the bean itself (a proxy, a stub), short-circuiting the container: no instantiation, injection or init callbacks; only postProcessAfterInitialization of the processors still runs on it. postProcessAfterInstantiation returning false skips the injection of the bean's fields and setters; postProcessProperties runs right after that injection (Spring's AutowiredAnnotationBeanPostProcessor injects there; in Dart the generated code does, so it is the hook to inject or check more).

// In tests, the remote client is replaced by a fake one.
class StubRemote extends InstantiationAwareBeanPostProcessor {
  @override
  Object? postProcessBeforeInstantiation(Type beanType, String beanName) =>
      beanType == RemoteClient ? FakeRemoteClient() : null;
}

Spring (Java):

class StubRemote implements InstantiationAwareBeanPostProcessor {
  public Object postProcessBeforeInstantiation(Class<?> type, String name) {
    return type == RemoteClient.class ? new FakeRemoteClient() : null;
  }
}
Inheritance

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

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
postProcessAfterInitialization(Object bean, String beanName) → Object
Called for each new bean after its init callbacks. The returned object (a proxy, say) is what the container exposes and injects. Also applied to FactoryBean products.
inherited
postProcessAfterInstantiation(Object bean, String beanName) → bool
Called right after bean was constructed. Return false to skip its field, setter and method injection (and the following postProcessProperties calls); true by default.
postProcessBeforeInitialization(Object bean, String beanName) → Object
Called for each new bean after injection and the aware callbacks, before the init callbacks (@PostConstruct, afterPropertiesSet, init method). Returns the object to go on with, usually bean itself.
inherited
postProcessBeforeInstantiation(Type beanType, String beanName) → Object?
The object to use as the bean beanName instead of creating one of beanType, or null (the default) to create it as usual. A returned object gets no injection, init or destroy callbacks; only postProcessAfterInitialization runs on it.
postProcessProperties(Object bean, String beanName) → void
Called after the fields and setters of bean were injected, before the aware callbacks and the init callbacks: the place to inject or check more.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited