public abstract class BeanConfiguration
extends java.lang.Object
BeanConfigurations must provide a public constructor, which takes the Context or no
arguments, to be instantiated.
Usage example:
// 1. extend BeanConfiguration:
public class MyBeanConfiguration extends BeanConfiguration {
// 2. declare dependencies to other beans using the require-methods:
private final BeanDependency<AnotherBean> dependency = requireBean(AnotherBean.class);
// 3. define beans:
public void defineBeans(BeansCollector beansCollector) {
beansCollector.defineBean(new MyBean(dependency.get()));
}
}
| Modifier and Type | Class and Description |
|---|---|
static class |
BeanConfiguration.Readiness |
| Constructor and Description |
|---|
BeanConfiguration() |
| Modifier and Type | Method and Description |
|---|---|
abstract void |
defineBeans(BeansCollector beansCollector)
Defines beans for the context of this application by calling
BeanConfigurationsBeansCollector.defineBean(String, Object) or
BeanConfigurationsBeansCollector.defineBean(Object). |
protected java.util.List<BeanDependency<?>> |
getDependencies()
Allows to express
BeanDependencys that must be fulfilled for this BeanConfiguration to define its
beans. |
BeanConfiguration.Readiness |
isReadyToDefineBeans(BeansProvider beansProvider)
Checks, if this
BeanConfiguration is ready to define its beans. |
protected <T> BeanDependency<T> |
requireBean(java.lang.Class<T> type)
Creates and registers a
BeanDependency on a bean of the given type. |
protected <T> BeanDependency<T> |
requireBean(java.lang.String name,
java.lang.Class<T> type)
Creates and registers a
BeanDependency on a bean with the given name and of the given type. |
protected <T> BeanDependency<java.util.List<T>> |
requireBeans(java.lang.Class<T> type)
Creates and registers a
BeanDependency on the beans of the given type. |
protected <T> BeanDependency<java8.util.Optional<T>> |
requireOptionalBean(java.lang.Class<T> type)
Creates and registers a
BeanDependency on a bean of the given type. |
protected final <T> BeanDependency<T> requireBean(java.lang.String name, java.lang.Class<T> type)
BeanDependency on a bean with the given name and of the given type.T - the type of the desired beanname - the name of the desired beantype - the type of the desired beanBeanDependency on the desired beanprotected final <T> BeanDependency<T> requireBean(java.lang.Class<T> type)
BeanDependency on a bean of the given type.T - the type of the desired beantype - the type of the desired beanBeanDependency on the desired beanprotected final <T> BeanDependency<java8.util.Optional<T>> requireOptionalBean(java.lang.Class<T> type)
BeanDependency on a bean of the given type.T - the type of the desired beantype - the type of the desired beanBeanDependency on the desired beanprotected final <T> BeanDependency<java.util.List<T>> requireBeans(java.lang.Class<T> type)
BeanDependency on the beans of the given type.T - the type of the desired beantype - the type of the desired beanBeanDependency on the desired beanprotected java.util.List<BeanDependency<?>> getDependencies()
BeanDependencys that must be fulfilled for this BeanConfiguration to define its
beans.
By default this method returns all BeanDependencys registered by the require-methods such as
requireBean(String, Class)
BeanDependencys of this BeanConfigurationpublic BeanConfiguration.Readiness isReadyToDefineBeans(BeansProvider beansProvider)
BeanConfiguration is ready to define its beans.
Therefor it tries to fulfill all its BeanDependencys
returned by getDependencies(). The Readiness is derived from the minimum
BeanDependency.Fulfillment of the BeanDependencys. If all are fulfilled the
BeanConfiguration is ready, if all are at least unfulfilled but optional the BeanConfiguration should be delayed to wait for additional
beans and if at least one BeanDependency is unfulfilled the
BeanConfiguration is unready.
beansProvider - the BeansProvider to fulfill BeanDependencysBeanConfiguration.Readiness of this BeanConfiguration to define its beanspublic abstract void defineBeans(BeansCollector beansCollector)
BeanConfigurationsBeansCollector.defineBean(String, Object) or
BeanConfigurationsBeansCollector.defineBean(Object).
Other beans can by obtained by declaring BeanDependencys to satisfy dependencies of the defined beans
through getDependencies(). Hence, the require-methods that register BeanDependencys must not be
called inside this method; this must be done earlier. And take care not to create cyclic dependencies between
BeanConfigurations which are unresolvable.
This method must not be called before isReadyToDefineBeans(BeansProvider) returned
true.
beansCollector - the BeanConfigurationsBeansCollector that collects the beansBeanConfigurationsBeansCollector.defineBean(String, Object),
BeanConfigurationsBeansCollector.defineBean(Object)