Interface Builder


public interface Builder
Mutable builder object used when building a bean scope.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Add field and method injection.
    void
    Add lifecycle PostConstruct method.
    void
    Add lifecycle PreDestroy method.
    build(boolean withShutdownHook)
    Build and return the bean scope.
    <T> T
    get(Class<T> cls)
    Get a dependency.
    <T> T
    get(Class<T> cls, String name)
    Get a named dependency.
    <T> T
    get(Type cls)
    Get a dependency for the generic type.
    <T> T
    get(Type cls, String name)
    Get a named dependency for the generic type.
    <T> T
    Get an optional dependency potentially returning null.
    <T> T
    getNullable(Class<T> cls, String name)
    Get an optional named dependency potentially returning null.
    <T> T
    Get an optional dependency potentially returning null for the generic type.
    <T> T
    getNullable(Type cls, String name)
    Get an optional named dependency potentially returning null for the generic type.
    <T> Optional<T>
    Get an optional dependency.
    <T> Optional<T>
    getOptional(Class<T> cls, String name)
    Get an optional named dependency.
    <T> Optional<T>
    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>
    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>
    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.
    boolean
    isAddBeanFor(Type... types)
    Return true if the bean should be created and registered with the context.
    boolean
    isAddBeanFor(String name, Type... types)
    Return true if the bean should be created and registered with the context.
    <T> List<T>
    list(Class<T> type)
    Get a list of dependencies for the type.
    <T> List<T>
    list(Type type)
    Get a list of dependencies for the generic type.
    <T> Map<String,T>
    map(Class<T> type)
    Return a map of dependencies for the type keyed by qualifier name.
    <T> Map<String,T>
    map(Type type)
    Return a map of dependencies for the generic type keyed by qualifier name.
    static Builder
    newBuilder(List<SuppliedBean> suppliedBeans, List<EnrichBean> enrichBeans, BeanScope parent, boolean parentOverride)
    Create the root level Builder.
    <T> T
    register(T bean)
    Register the bean instance into the context.
    <T> T
    Register the bean as a Primary bean.
    <T> void
    registerProvider(jakarta.inject.Provider<T> provider)
    Register the provider into the context.
    <T> T
    Register the bean as a secondary bean.
    <T> Set<T>
    set(Class<T> type)
    Get a set of dependencies for the type.
    <T> Set<T>
    set(Type type)
    Get a set of dependencies for the generic type.
    <T> void
    withBean(Class<T> type, T bean)
    Register the externally provided bean.
  • Method Details

    • newBuilder

      static Builder newBuilder(List<SuppliedBean> suppliedBeans, List<EnrichBean> enrichBeans, BeanScope parent, boolean parentOverride)
      Create the root level Builder.
      Parameters:
      suppliedBeans - The list of beans (typically test doubles) supplied when building the context.
      enrichBeans - The list of classes we want to have with mockito spy enhancement
      parent - The parent BeanScope
      parentOverride - When false do not add beans that already exist on the parent
    • isAddBeanFor

      boolean isAddBeanFor(String name, Type... types)
      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 name
      types - The types that the bean implements and provides
    • isAddBeanFor

      boolean isAddBeanFor(Type... types)
      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
    • registerProvider

      <T> void registerProvider(jakarta.inject.Provider<T> provider)
      Register the provider into the context.
    • register

      <T> T register(T bean)
      Register the bean instance into the context.
      Parameters:
      bean - The bean instance that has been created.
    • registerPrimary

      <T> T registerPrimary(T bean)
      Register the bean as a Primary bean.
    • registerSecondary

      <T> T registerSecondary(T bean)
      Register the bean as a secondary bean.
    • withBean

      <T> void withBean(Class<T> type, T bean)
      Register the externally provided bean.
      Parameters:
      type - The type of the provided bean.
      bean - The bean instance
    • addPostConstruct

      void addPostConstruct(Runnable runnable)
      Add lifecycle PostConstruct method.
    • addPreDestroy

      void addPreDestroy(AutoCloseable closeable)
      Add lifecycle PreDestroy method.
    • addInjector

      void addInjector(Consumer<Builder> injector)
      Add field and method injection.
    • get

      <T> T get(Class<T> cls)
      Get a dependency.
    • get

      <T> T get(Class<T> cls, String name)
      Get a named dependency.
    • get

      <T> T get(Type cls)
      Get a dependency for the generic type.
    • get

      <T> T get(Type cls, String name)
      Get a named dependency for the generic type.
    • 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.
    • getOptional

      <T> Optional<T> getOptional(Type cls)
      Get an optional dependency for the generic type.
    • getOptional

      <T> Optional<T> getOptional(Type cls, String name)
      Get an optional named dependency for the generic type.
    • getNullable

      <T> T getNullable(Class<T> cls)
      Get an optional dependency potentially returning null.
    • getNullable

      <T> T getNullable(Class<T> cls, String name)
      Get an optional named dependency potentially returning null.
    • getNullable

      <T> T getNullable(Type cls)
      Get an optional dependency potentially returning null for the generic type.
    • getNullable

      <T> T getNullable(Type cls, String name)
      Get an optional named dependency potentially returning null for the generic type.
    • getProvider

      <T> jakarta.inject.Provider<T> getProvider(Class<T> cls)
      Return Provider of T given the type.
    • getProvider

      <T> jakarta.inject.Provider<T> getProvider(Class<T> cls, String name)
      Return Provider of T given the type and name.
    • getProvider

      <T> jakarta.inject.Provider<T> getProvider(Type cls)
      Return Provider of T given the generic type.
    • getProvider

      <T> jakarta.inject.Provider<T> getProvider(Type cls, String name)
      Return Provider of T given the generic type and name.
    • getProviderFor

      <T> jakarta.inject.Provider<T> getProviderFor(Class<?> cls, Type type)
      Return Provider for a generic interface type.
      Parameters:
      cls - The usual implementation class
      type - The generic interface type
    • list

      <T> List<T> list(Class<T> type)
      Get a list of dependencies for the type.
    • list

      <T> List<T> list(Type type)
      Get a list of dependencies for the generic type.
    • set

      <T> Set<T> set(Class<T> type)
      Get a set of dependencies for the type.
    • set

      <T> Set<T> set(Type type)
      Get a set of dependencies for the generic type.
    • map

      <T> Map<String,T> map(Class<T> type)
      Return a map of dependencies for the type keyed by qualifier name.
    • map

      <T> Map<String,T> map(Type type)
      Return a map of dependencies for the generic type keyed by qualifier name.
    • build

      BeanScope build(boolean withShutdownHook)
      Build and return the bean scope.