Interface Builder
public interface Builder
Mutable builder object used when building a bean scope.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddAutoClosable(Object maybeAutoCloseable) Check if the instance is AutoCloseable and if so register it with PreDestroy.voidaddInjector(Consumer<Builder> injector) Add field and method injection.voidaddPostConstruct(Runnable runnable) Add lifecycle PostConstruct method.voidaddPostConstruct(Consumer<BeanScope> consumer) Add lifecycle PostConstruct method.voidaddPreDestroy(AutoCloseable closeable) Add lifecycle PreDestroy method.voidaddPreDestroy(AutoCloseable closeable, int priority) Add lifecycle PreDestroy method with a given priority.Register the next bean as having Primary priority.asPriority(int priority) Register the next bean as having the given priority.Register the next bean as having Prototype scope.Register the next bean as having Secondary priority.build(boolean withShutdownHook, long start) Build and return the bean scope.booleanReturn true if the builder contains the given type.booleanReturn true if the builder contains the given type.booleancontainsAllProfiles(List<String> type) Return true if the builder contains all of the given profilebooleancontainsProfiles(List<String> type) Return true if the builder contains the given profilebooleancontainsQualifier(String name) Return true if the builder contains a bean with the given name.voidcurrentModule(Class<? extends AvajeModule> currentModule) Set the current module being wired.voidcurrentScopes(String[] scopes) Set the custom scopes defined by the module being wired.<T> TGet a dependency.<T> TGet a named dependency.<T> TGet a dependency for the generic type.<T> TGet a named dependency for the generic type.<T> TgetNullable(Class<T> cls) Get an optional dependency potentially returning null.<T> TgetNullable(Class<T> cls, String name) Get an optional named dependency potentially returning null.<T> TgetNullable(Type cls) Get an optional dependency potentially returning null for the generic type.<T> TgetNullable(Type cls, String name) Get an optional named dependency potentially returning null for the generic type.<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.<T> Optional<T> getOptional(Type cls) Get an optional dependency for the generic type.<T> Optional<T> getOptional(Type cls, String name) Get an optional named dependency for the generic type.<T> jakarta.inject.Provider<T> getProvider(Class<T> cls) Return Provider of T given the type.<T> jakarta.inject.Provider<T> getProvider(Class<T> cls, String name) Return Provider of T given the type and name.<T> jakarta.inject.Provider<T> getProvider(Type cls) Return Provider of T given the generic type.<T> jakarta.inject.Provider<T> getProvider(Type cls, String name) Return Provider of T given the generic type and name.<T> jakarta.inject.Provider<T> getProviderFor(Class<?> cls, Type type) Return Provider for a generic interface type.default booleanisBeanAbsent(Type... types) Return true if the bean should be created and registered with the context.booleanisBeanAbsent(String name, Type... types) Return true if the bean should be created and registered with the context.<T> List<T> Get a list of dependencies for the type.<T> List<T> Get a list of dependencies for the generic type.<T> List<T> Get a list of dependencies for the type and name.Return a map of dependencies for the type keyed by qualifier name.Return a map of dependencies for the generic type keyed by qualifier name.static BuildernewBuilder(Set<String> profiles, ConfigPropertyPlugin plugin, List<SuppliedBean> suppliedBeans, List<EnrichBean> enrichBeans, BeanScope parent, boolean parentOverride) Create the root level Builder.property()Return the plugin for required properties.<T> Tregister(T bean) Register the bean instance into the context.default <T> voidregisterLazy(jakarta.inject.Provider<T> provider, Function<jakarta.inject.Provider<T>, T> proxyClassConstructor) Register the lazy provider into the context.<T> voidregisterProvider(jakarta.inject.Provider<T> provider) Register the provider into the context.<T> Set<T> Get a set of dependencies for the type.<T> Set<T> Get a set of dependencies for the generic type.<T> Set<T> Get a set of dependencies for the type and name.<T> voidRegister the externally provided bean.
-
Method Details
-
newBuilder
static Builder newBuilder(Set<String> profiles, ConfigPropertyPlugin plugin, List<SuppliedBean> suppliedBeans, List<EnrichBean> enrichBeans, BeanScope parent, boolean parentOverride) Create the root level Builder.- Parameters:
profiles- Explicit profiles usedsuppliedBeans- The list of beans (typically test doubles) supplied when building the context.enrichBeans- The list of classes we want to have with mockito spy enhancementparent- The parent BeanScopeparentOverride- When false do not add beans that already exist on the parent
-
isBeanAbsent
Return true if the bean should be created and registered with the context.Returning false means there has been a supplied bean already registered and that we should skip the creation and registration for this bean.
- Parameters:
name- The qualifier nametypes- The types that the bean implements and provides
-
isBeanAbsent
Return true if the bean should be created and registered with the context.Returning false means there has been a supplied bean already registered and that we should skip the creation and registration for this bean.
- Parameters:
types- The types that the bean implements and provides
-
asPrimary
-
asSecondary
Register the next bean as having Secondary priority. Lowest priority, wired when no other matching beans are available. -
asPriority
Register the next bean as having the given priority. Wired only if no other higher priority matching beans are available. -
asPrototype
Register the next bean as having Prototype scope. -
registerProvider
Register the provider into the context. -
registerLazy
default <T> void registerLazy(jakarta.inject.Provider<T> provider, Function<jakarta.inject.Provider<T>, T> proxyClassConstructor) Register the lazy provider into the context. -
register
Register the bean instance into the context.- Parameters:
bean- The bean instance that has been created.
-
withBean
-
addPostConstruct
Add lifecycle PostConstruct method. -
addPostConstruct
Add lifecycle PostConstruct method. -
addPreDestroy
Add lifecycle PreDestroy method. -
addPreDestroy
Add lifecycle PreDestroy method with a given priority. -
addAutoClosable
Check if the instance is AutoCloseable and if so register it with PreDestroy.- Parameters:
maybeAutoCloseable- An instance that might be AutoCloseable
-
addInjector
Add field and method injection. -
get
-
get
-
get
-
get
-
getOptional
Get an optional dependency. -
getOptional
Get an optional named dependency. -
getOptional
Get an optional dependency for the generic type. -
getOptional
Get an optional named dependency for the generic type. -
getNullable
Get an optional dependency potentially returning null. -
getNullable
Get an optional named dependency potentially returning null. -
getNullable
Get an optional dependency potentially returning null for the generic type. -
getNullable
Get an optional named dependency potentially returning null for the generic type. -
getProvider
Return Provider of T given the type. -
getProvider
Return Provider of T given the type and name. -
getProvider
Return Provider of T given the generic type. -
getProvider
Return Provider of T given the generic type and name. -
getProviderFor
Return Provider for a generic interface type.- Parameters:
cls- The usual implementation classtype- The generic interface type
-
list
-
list
-
list
-
set
-
set
-
set
-
map
-
map
-
contains
-
contains
-
containsQualifier
Return true if the builder contains a bean with the given name. -
containsProfiles
Return true if the builder contains the given profile -
containsAllProfiles
Return true if the builder contains all of the given profile -
property
Return the plugin for required properties. -
build
-
currentModule
Set the current module being wired. -
currentScopes
Set the custom scopes defined by the module being wired.
-