Package io.avaje.inject.core
Interface Builder
-
public interface Builder
Mutable builder object used when building a bean context.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddChild(BeanContext context)Add a child context.voidaddInjector(Consumer<Builder> injector)Add a field injector.voidaddLifecycle(BeanLifecycle bean)Add a lifecycle bean.BeanContextbuild()Build and return the bean context.<T> BeanEntry<T>candidate(Class<T> cls, String name)Get a candidate dependency allowing it to be null.<T> Tenrich(T bean, Class<?>[] types)Return a potentially enriched bean for registration into the context.<T> Tget(Class<T> cls)Get a dependency.<T> Tget(Class<T> cls, String name)Get a named dependency.String[]getDependsOn()Return the names of modules that this module depends on.<T> List<T>getList(Class<T> interfaceType)Get a list of dependencies for the interface type .StringgetName()Return the name of the (module) context this builder is creating.<T> Optional<T>getOptional(Class<T> cls)Get an optional dependency.<T> Optional<T>getOptional(Class<T> cls, String name)Get an optional named dependency.String[]getProvides()Return the names of module features that this module provides.<T> Set<T>getSet(Class<T> interfaceType)Get a set of dependencies for the interface type .booleanisAddBeanFor(Class<?> injectTarget)Return true if the bean should be created and registered with the context.booleanisAddBeanFor(Class<?> addForType, Class<?> injectTarget)Return true if the bean should be created and registered with the context.<T> Tregister(T bean, String name, Class<?>... types)Register the bean instance into the context.<T> TregisterPrimary(T bean, String name, Class<?>... types)Register the bean as a Primary bean.<T> TregisterSecondary(T bean, String name, Class<?>... types)Register the bean as a secondary bean.voidsetParent(Builder parent)Set a parent builder that can provide cross-module dependencies.
-
-
-
Method Detail
-
getProvides
String[] getProvides()
Return the names of module features that this module provides.
-
getDependsOn
String[] getDependsOn()
Return the names of modules that this module depends on.
-
setParent
void setParent(Builder parent)
Set a parent builder that can provide cross-module dependencies.
-
isAddBeanFor
boolean isAddBeanFor(Class<?> addForType, Class<?> injectTarget)
Return true if the bean should be created and registered with the context. Returning false means there has been a (test double) bean already registered and that we should skip the creation and registration for this bean.- Parameters:
addForType- The interface that the bean implements and providesinjectTarget- The actual bean type we are looking to create and register
-
isAddBeanFor
boolean isAddBeanFor(Class<?> injectTarget)
Return true if the bean should be created and registered with the context. Returning false means there has been a (test double) bean already registered and that we should skip the creation and registration for this bean.- Parameters:
injectTarget- The actual bean type we are looking to create and register
-
register
<T> T register(T bean, String name, Class<?>... types)
Register the bean instance into the context.Beans are added in an appropriate order to satisfy dependencies.
- Parameters:
bean- The bean instance that has been created.name- The (optional) name of the instance.types- Interfaces and class level annotations this bean provides or associates to.
-
registerPrimary
<T> T registerPrimary(T bean, String name, Class<?>... types)
Register the bean as a Primary bean.
-
registerSecondary
<T> T registerSecondary(T bean, String name, Class<?>... types)
Register the bean as a secondary bean.
-
addLifecycle
void addLifecycle(BeanLifecycle bean)
Add a lifecycle bean.
-
addInjector
void addInjector(Consumer<Builder> injector)
Add a field injector.
-
addChild
void addChild(BeanContext context)
Add a child context.
-
getOptional
<T> Optional<T> getOptional(Class<T> cls)
Get an optional dependency.
-
getOptional
<T> Optional<T> getOptional(Class<T> cls, String name)
Get an optional named dependency.
-
getList
<T> List<T> getList(Class<T> interfaceType)
Get a list of dependencies for the interface type .
-
getSet
<T> Set<T> getSet(Class<T> interfaceType)
Get a set of dependencies for the interface type .
-
candidate
<T> BeanEntry<T> candidate(Class<T> cls, String name)
Get a candidate dependency allowing it to be null.
-
build
BeanContext build()
Build and return the bean context.
-
enrich
<T> T enrich(T bean, Class<?>[] types)
Return a potentially enriched bean for registration into the context. Typically for use with mockito spy.- Parameters:
bean- The bean with dependencies injectedtypes- The types this bean registers for- Returns:
- Either the bean or the enriched bean to register into the context.
-
-