Interface Module.WrapperBeanBuilder<P,T,W extends Supplier<T>>
- Type Parameters:
P
- the type provided by the bean to buildT
- the actual type of the bean to buildW
- the bean wrapper which supplies the bean instance
- All Superinterfaces:
Module.BeanBuilder<W,
Module.WrapperBeanBuilder<P, T, W>>
- Enclosing class:
Module
A BeanBuilder for creating wrapper Module.Bean
instances.
A wrapper Module.Bean
instance is built from a Supplier
used to obtain a wrapper instance which wraps the actual bean instance creation, initialization and destruction logic and defer
the actual instantiation of the bean. Initialization and destruction operations are invoked on the wrapper instance (after dependency injection) and before its destruction respectively.
Particular care must be taken when a prototype wrapper bean is created as the wrapper bean instance must not hold any strong reference to the actual bean instance in order to prevent memory
leaks. In that case, using a WeakReference
is strongly advised.
this.bean = WrapperBeanBuilder
.singleton("bean", () -> {
BeanA beanA = new BeanA(serviceSocket.get());
return beanA;
})
.init(BeanA::init)
.destroy(BeanA::destroy)
.build(this);
- Since:
- 1.0
- Author:
- Jeremy Kuhn
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.inverno.core.v1.Module.BeanBuilder
Module.BeanBuilder.FallibleConsumer<T>
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds the bean.<P> Module.WrapperBeanBuilder
<P, T, W> Specifies an override that, when present, provides bean instances instead of the builder.static <T,
W extends Supplier<T>>
Module.WrapperBeanBuilder<T, T, W> Returns a prototype wrapper bean builder.static <T,
W extends Supplier<T>>
Module.WrapperBeanBuilder<T, T, W> Returns a singleton wrapper bean builder.Methods inherited from interface io.inverno.core.v1.Module.BeanBuilder
destroy, init
-
Method Details
-
singleton
static <T,W extends Supplier<T>> Module.WrapperBeanBuilder<T,T, singletonW> (String beanName, Supplier<W> constructor) Returns a singleton wrapper bean builder.
Singleton
Module.Bean
s are useful when one single instance of a bean should be injected through the application.- Type Parameters:
T
- the type of the bean to buildW
- the bean wrapper which supplies the bean instance- Parameters:
beanName
- the bean nameconstructor
- the bean instance supplier- Returns:
- a singleton Bean Builder
-
prototype
static <T,W extends Supplier<T>> Module.WrapperBeanBuilder<T,T, prototypeW> (String beanName, Supplier<W> constructor) Returns a prototype wrapper bean builder.
Prototype
Module.Bean
s are useful when distinct instances of a bean should be injected though the application.- Type Parameters:
T
- the type of the bean to buildW
- the bean wrapper which supplies the bean instance- Parameters:
beanName
- the bean nameconstructor
- the bean instance supplier- Returns:
- a prototype Bean Builder
-
build
Module.Bean<P> build()Builds the bean.
- Returns:
- a bean
-
override
Specifies an override that, when present, provides bean instances instead of the builder.
- Type Parameters:
P
- the type provided by the override and therefore the bean to build- Parameters:
override
- An optional override- Returns:
- this builder
-