Class DefaultBeanContext

java.lang.Object
io.micronaut.context.DefaultBeanContext
All Implemented Interfaces:
BeanContext, BeanDefinitionRegistry, BeanLocator, ConfigurableBeanContext, ApplicationEventPublisher<Object>, ExecutionHandleLocator, LifeCycle<BeanContext>, AnnotationMetadataResolver, AttributeHolder, MutableAttributeHolder, ConversionServiceProvider, Closeable, AutoCloseable

@Internal @NextMajorVersion("Remove public in v6") public sealed class DefaultBeanContext extends Object implements ConfigurableBeanContext
The default context implementations.
Since:
1.0
Author:
Graeme Rocher
  • Field Details

    • LOG

      protected static final org.slf4j.Logger LOG
    • LOG_LIFECYCLE

      protected static final org.slf4j.Logger LOG_LIFECYCLE
    • MSG_BEAN_DEFINITION

      public static final String MSG_BEAN_DEFINITION
      See Also:
    • running

      protected final AtomicBoolean running
    • configured

      protected final AtomicBoolean configured
    • initializing

      protected final AtomicBoolean initializing
    • terminating

      protected final AtomicBoolean terminating
    • singletonScope

      protected final io.micronaut.context.SingletonScope singletonScope
    • conversionService

      protected MutableConversionService conversionService
    • beanDefinitionProvider

      protected final BeanDefinitionService beanDefinitionProvider
  • Constructor Details

    • DefaultBeanContext

      public DefaultBeanContext()
      Construct a new bean context using the same classloader that loaded this DefaultBeanContext class.
    • DefaultBeanContext

      public DefaultBeanContext(@NonNull ClassLoader classLoader)
      Construct a new bean context with the given class loader.
      Parameters:
      classLoader - The class loader
    • DefaultBeanContext

      public DefaultBeanContext(@NonNull ClassPathResourceLoader resourceLoader)
      Construct a new bean context with the given class loader.
      Parameters:
      resourceLoader - The resource loader
    • DefaultBeanContext

      public DefaultBeanContext(@NonNull BeanContextConfiguration contextConfiguration)
      Creates a new bean context with the given configuration.
      Parameters:
      contextConfiguration - The context configuration
  • Method Details

    • createCustomScopeRegistry

      protected @NonNull CustomScopeRegistry createCustomScopeRegistry()
      Allows customizing the custom scope registry.
      Returns:
      The custom scope registry to use.
      Since:
      3.0.0
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface LifeCycle<BeanContext>
      Returns:
      Whether the component is running
    • start

      public BeanContext start()
      The start method will read all bean definition classes found on the classpath and initialize any pre-required state.
      Specified by:
      start in interface LifeCycle<BeanContext>
      Returns:
      This lifecycle component
    • registerConversionService

      protected void registerConversionService()
      Registers conversion service.
    • stop

      public BeanContext stop()
      The close method will shut down the context calling PreDestroy hooks on loaded singletons.
      Specified by:
      stop in interface LifeCycle<BeanContext>
      Returns:
      This lifecycle component
    • resolveMetadata

      public @NonNull AnnotationMetadata resolveMetadata(Class<?> type)
      Description copied from interface: AnnotationMetadataResolver
      Resolve the AnnotationMetadata for the given type.
      Specified by:
      resolveMetadata in interface AnnotationMetadataResolver
      Parameters:
      type - The type
      Returns:
      The AnnotationMetadata
    • refreshBean

      public <T> Optional<T> refreshBean(@Nullable BeanIdentifier identifier)
      Description copied from interface: BeanContext

      Refresh the state of the given registered bean applying dependency injection and configuration wiring again.

      Note that if the bean was produced by a Factory then this method will refresh the factory too

      Specified by:
      refreshBean in interface BeanContext
      Type Parameters:
      T - The concrete class
      Parameters:
      identifier - The BeanIdentifier
      Returns:
      An Optional of the instance if it exists for the given registration
    • refreshBean

      public <T> void refreshBean(@NonNull BeanRegistration<T> beanRegistration)
      Description copied from interface: BeanContext

      Refresh the state of the given registered bean applying dependency injection and configuration wiring again.

      Note that if the bean was produced by a Factory then this method will refresh the factory too

      This methods skips an additional resolution of the BeanRegistration.
      Specified by:
      refreshBean in interface BeanContext
      Type Parameters:
      T - The concrete class
      Parameters:
      beanRegistration - The BeanRegistration
    • getActiveBeanRegistrations

      public Collection<BeanRegistration<?>> getActiveBeanRegistrations(Qualifier<?> qualifier)
      Description copied from interface: BeanDefinitionRegistry
      Find active Singleton beans for the given qualifier. Note that this method can return multiple registrations for a given singleton bean instance since each bean may have multiple qualifiers.
      Specified by:
      getActiveBeanRegistrations in interface BeanDefinitionRegistry
      Parameters:
      qualifier - The qualifier
      Returns:
      The beans
    • getActiveBeanRegistrations

      public <T> Collection<BeanRegistration<T>> getActiveBeanRegistrations(Class<T> beanType)
      Description copied from interface: BeanDefinitionRegistry
      Find active Singleton beans for the given bean type. Note that this method can return multiple registrations for a given singleton bean instance since each bean may have multiple qualifiers.
      Specified by:
      getActiveBeanRegistrations in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The bean type
      Returns:
      The beans
    • getBeanRegistrations

      public <T> Collection<BeanRegistration<T>> getBeanRegistrations(Class<T> beanType)
      Description copied from interface: BeanDefinitionRegistry
      Find and if necessary initialize Singleton beans for the given bean type, returning all the active registrations. Note that this method can return multiple registrations for a given singleton bean instance since each bean may have multiple qualifiers.
      Specified by:
      getBeanRegistrations in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The bean type
      Returns:
      The beans
    • getBeanRegistration

      public <T> BeanRegistration<T> getBeanRegistration(Class<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanDefinitionRegistry
      Find a bean registration for the given bean type and optional qualifier.
      Specified by:
      getBeanRegistration in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The bean registration
    • getBeanRegistrations

      public <T> Collection<BeanRegistration<T>> getBeanRegistrations(Class<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanDefinitionRegistry
      Find and if necessary initialize Singleton beans for the given bean type, returning all the active registrations. Note that this method can return multiple registrations for a given singleton bean instance since each bean may have multiple qualifiers.
      Specified by:
      getBeanRegistrations in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The beans
    • getBeanRegistrations

      public <T> Collection<BeanRegistration<T>> getBeanRegistrations(Argument<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanDefinitionRegistry
      Find and if necessary initialize Singleton beans for the given bean type, returning all the active registrations. Note that this method can return multiple registrations for a given singleton bean instance since each bean may have multiple qualifiers.
      Specified by:
      getBeanRegistrations in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The beans
    • getBeanRegistration

      public <T> BeanRegistration<T> getBeanRegistration(Argument<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanDefinitionRegistry
      Find a bean registration for the given bean type and optional qualifier.
      Specified by:
      getBeanRegistration in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      The bean registration
    • getBeanRegistration

      public <T> BeanRegistration<T> getBeanRegistration(BeanDefinition<T> beanDefinition)
      Description copied from interface: BeanDefinitionRegistry
      Find a bean registration for the given bean definition.
      Specified by:
      getBeanRegistration in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanDefinition - The bean definition
      Returns:
      The bean registration
    • findBeanRegistration

      public <T> Optional<BeanRegistration<T>> findBeanRegistration(T bean)
      Description copied from interface: BeanDefinitionRegistry
      Obtain a BeanRegistration for the given bean.
      Specified by:
      findBeanRegistration in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      bean - The bean
      Returns:
      An Optional of the bean definition
    • findExecutionHandle

      public <T, R> Optional<MethodExecutionHandle<T,R>> findExecutionHandle(Class<T> beanType, String method, Class<?>... arguments)
      Description copied from interface: ExecutionHandleLocator
      Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be implemented by generated byte code.
      Specified by:
      findExecutionHandle in interface ExecutionHandleLocator
      Type Parameters:
      T - The target bean
      R - The result type of the execution handle
      Parameters:
      beanType - The bean type
      method - The method
      arguments - The arguments
      Returns:
      The execution handle
    • createExecutionHandle

      public MethodExecutionHandle<?,Object> createExecutionHandle(BeanDefinition<?> beanDefinition, ExecutableMethod<Object,?> method)
      Description copied from interface: ExecutionHandleLocator
      Create an execution handle for the given bean definition and method.
      Specified by:
      createExecutionHandle in interface ExecutionHandleLocator
      Parameters:
      beanDefinition - The bean definition
      method - The method
      Returns:
      The execution handle
    • findExecutionHandle

      public <T, R> Optional<MethodExecutionHandle<T,R>> findExecutionHandle(Class<T> beanType, Qualifier<?> q, String method, Class<?>... arguments)
      Description copied from interface: ExecutionHandleLocator
      Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be implemented by generated byte code.
      Specified by:
      findExecutionHandle in interface ExecutionHandleLocator
      Type Parameters:
      T - The target bean
      R - The result type of the execution handle
      Parameters:
      beanType - The bean type
      q - The bean qualifer
      method - The method
      arguments - The arguments
      Returns:
      The execution handle
    • findExecutableMethod

      public <T, R> Optional<ExecutableMethod<T,R>> findExecutableMethod(Class<T> beanType, String method, Class<?>[] arguments)
      Description copied from interface: ExecutionHandleLocator
      Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be implemented by generated byte code.
      Specified by:
      findExecutableMethod in interface ExecutionHandleLocator
      Type Parameters:
      T - The bean type class
      R - The result type of the execution handle
      Parameters:
      beanType - The bean type
      method - The method
      arguments - The arguments
      Returns:
      The execution handle
    • findExecutionHandle

      public <T, R> Optional<MethodExecutionHandle<T,R>> findExecutionHandle(T bean, String method, Class<?>[] arguments)
      Description copied from interface: ExecutionHandleLocator
      Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be implemented by generated byte code.
      Specified by:
      findExecutionHandle in interface ExecutionHandleLocator
      Type Parameters:
      T - The target bean
      R - The result type of the execution handle
      Parameters:
      bean - The bean to invoke the method on
      method - The method
      arguments - The arguments
      Returns:
      The execution handle
    • registerSingleton

      public <T> BeanContext registerSingleton(@NonNull Class<T> type, @NonNull T singleton, Qualifier<T> qualifier, boolean inject)
      Description copied from interface: BeanDefinitionRegistry

      Registers a new singleton bean at runtime. This method expects that the bean definition data will have been compiled ahead of time.

      If bean definition data is found the method will perform dependency injection on the instance followed by invoking any PostConstruct hooks.

      If no bean definition data is found the bean is registered as is.

      Specified by:
      registerSingleton in interface BeanContext
      Specified by:
      registerSingleton in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      type - The bean type
      singleton - The singleton bean
      qualifier - The bean qualifier
      inject - Whether the singleton should be injected (defaults to true)
      Returns:
      This bean context
    • getClassLoader

      public ClassLoader getClassLoader()
      Specified by:
      getClassLoader in interface BeanContext
      Returns:
      The class loader used by this context
    • getBeanValidator

      public BeanDefinitionValidator getBeanValidator()
      Specified by:
      getBeanValidator in interface BeanContext
      Returns:
      Get the configured bean validator, if any.
    • findBeanConfiguration

      public Optional<BeanConfiguration> findBeanConfiguration(String configurationName)
      Description copied from interface: BeanDefinitionRegistry
      Obtain a bean configuration by name.
      Specified by:
      findBeanConfiguration in interface BeanDefinitionRegistry
      Parameters:
      configurationName - The configuration name
      Returns:
      An optional with the configuration either present or not
    • getBeanDefinition

      public <T> BeanDefinition<T> getBeanDefinition(Argument<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanDefinitionRegistry
      Obtain a BeanDefinition for the given type.
      Specified by:
      getBeanDefinition in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The potentially parameterized type
      qualifier - The qualifier
      Returns:
      The BeanDefinition
    • findBeanDefinition

      public <T> Optional<BeanDefinition<T>> findBeanDefinition(Argument<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanDefinitionRegistry
      Obtain a BeanDefinition for the given type.
      Specified by:
      findBeanDefinition in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The potentially parameterized type
      qualifier - The qualifier
      Returns:
      An Optional of the bean definition
    • findBeanDefinition

      public <T> Optional<BeanDefinition<T>> findBeanDefinition(Class<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanDefinitionRegistry
      Obtain a BeanDefinition for the given type.
      Specified by:
      findBeanDefinition in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The type
      qualifier - The qualifier
      Returns:
      An Optional of the bean definition
    • getBeanDefinitions

      public <T> Collection<BeanDefinition<T>> getBeanDefinitions(Class<T> beanType)
      Description copied from interface: BeanDefinitionRegistry
      Obtain a BeanDefinition for the given type.
      Specified by:
      getBeanDefinitions in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The type
      Returns:
      An Optional of the bean definition
    • getBeanDefinitions

      public <T> Collection<BeanDefinition<T>> getBeanDefinitions(Argument<T> beanType)
      Description copied from interface: BeanDefinitionRegistry
      Obtain a BeanDefinition for the given type.
      Specified by:
      getBeanDefinitions in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The type
      Returns:
      An Optional of the bean definition
    • getBeanDefinitions

      public <T> Collection<BeanDefinition<T>> getBeanDefinitions(Class<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanDefinitionRegistry
      Obtain a BeanDefinition for the given type.
      Specified by:
      getBeanDefinitions in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The type
      qualifier - The qualifier
      Returns:
      An Optional of the bean definition
    • getBeanDefinitions

      public <T> Collection<BeanDefinition<T>> getBeanDefinitions(Argument<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanDefinitionRegistry
      Obtain a BeanDefinition for the given type.
      Specified by:
      getBeanDefinitions in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The type
      qualifier - The qualifier
      Returns:
      An Optional of the bean definition
    • containsBean

      public <T> boolean containsBean(@NonNull Class<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanDefinitionRegistry
      Return whether the bean of the given type is contained within this context.
      Specified by:
      containsBean in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The bean type
      qualifier - The qualifier for the bean
      Returns:
      True if it is
    • containsBean

      public <T> boolean containsBean(Argument<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanDefinitionRegistry
      Return whether the bean of the given type is contained within this context.
      Specified by:
      containsBean in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The bean type
      qualifier - The qualifier for the bean
      Returns:
      True if it is
    • getBean

      public <T> @NonNull T getBean(@NonNull Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Obtains a Bean for the given type and qualifier.
      Specified by:
      getBean in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      An instanceof said bean
      See Also:
    • getBean

      public <T> @NonNull T getBean(@NonNull Class<T> beanType)
      Description copied from interface: BeanLocator
      Obtains a Bean for the given type.
      Specified by:
      getBean in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      Returns:
      An instanceof said bean
    • getBean

      public <T> @NonNull T getBean(@NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Obtains a Bean for the given type and qualifier.
      Specified by:
      getBean in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      An instanceof said bean
      See Also:
    • findBean

      public <T> Optional<T> findBean(Class<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Finds a Bean for the given type and qualifier.
      Specified by:
      findBean in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      An instance of Optional that is either empty or containing the specified bean
      See Also:
    • findBean

      public <T> Optional<T> findBean(Argument<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Finds a Bean for the given type and qualifier.
      Specified by:
      findBean in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      An instance of Optional that is either empty or containing the specified bean
      See Also:
    • getBeansOfType

      public <T> Collection<T> getBeansOfType(Class<T> beanType)
      Description copied from interface: BeanLocator
      Get all beans of the given type.
      Specified by:
      getBeansOfType in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      Returns:
      The found beans
    • getBeansOfType

      public <T> Collection<T> getBeansOfType(Class<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Get all beans of the given type.
      Specified by:
      getBeansOfType in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The found beans
    • getBeansOfType

      public <T> Collection<T> getBeansOfType(Argument<T> beanType)
      Description copied from interface: BeanLocator
      Get all beans of the given type.
      Specified by:
      getBeansOfType in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potenitally parameterized bean type
      Returns:
      The found beans
    • getBeansOfType

      public <T> Collection<T> getBeansOfType(Argument<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Get all beans of the given type.
      Specified by:
      getBeansOfType in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potenitally parameterized bean type
      qualifier - The qualifier
      Returns:
      The found beans
    • streamOfType

      public <T> Stream<T> streamOfType(Class<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Obtain a stream of beans of the given type.
      Specified by:
      streamOfType in interface BeanLocator
      Type Parameters:
      T - The bean concrete type
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      A stream of instances
      See Also:
    • streamOfType

      public <T> Stream<T> streamOfType(Argument<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Obtain a stream of beans of the given type.
      Specified by:
      streamOfType in interface BeanLocator
      Type Parameters:
      T - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      A stream of instances
      See Also:
    • mapOfType

      public <V> Map<String,V> mapOfType(Argument<V> beanType, Qualifier<V> qualifier)
      Description copied from interface: BeanLocator
      Obtain a map of beans of the given type where the key is the qualifier.
      Specified by:
      mapOfType in interface BeanLocator
      Type Parameters:
      V - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      A map of instances
      See Also:
    • streamOfType

      protected <T> Stream<T> streamOfType(BeanResolutionContext resolutionContext, Class<T> beanType, Qualifier<T> qualifier)
      Obtains a stream of beans of the given type and qualifier.
      Type Parameters:
      T - The bean concrete type
      Parameters:
      resolutionContext - The bean resolution context
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      A stream
    • mapOfType

      protected <V> @NonNull Map<String,V> mapOfType(@Nullable BeanResolutionContext resolutionContext, @NonNull Argument<V> beanType, @Nullable Qualifier<V> qualifier)
      Obtains a map of beans of the given type and qualifier.
      Type Parameters:
      V - The bean type
      Parameters:
      resolutionContext - The resolution context
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      A map of beans, never null.
      Since:
      4.0.0
    • streamOfType

      @Internal public <T> Stream<T> streamOfType(BeanResolutionContext resolutionContext, Argument<T> beanType, Qualifier<T> qualifier)
      Obtains a stream of beans of the given type and qualifier.
      Type Parameters:
      T - The bean concrete type
      Parameters:
      resolutionContext - The bean resolution context
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      A stream
    • inject

      public <T> @NonNull T inject(@NonNull T instance)
      Description copied from interface: BeanContext
      Inject an existing instance.
      Specified by:
      inject in interface BeanContext
      Type Parameters:
      T - The bean generic type
      Parameters:
      instance - The instance to inject
      Returns:
      The instance to inject
    • createBean

      public <T> @NonNull T createBean(@NonNull Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanContext
      Creates a new instance of the given bean performing dependency injection and returning a new instance.

      Note that the instance returned is not saved as a singleton in the context.

      Specified by:
      createBean in interface BeanContext
      Type Parameters:
      T - The bean generic type
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The instance
    • createBean

      public <T> @NonNull T createBean(@NonNull Class<T> beanType, @Nullable Qualifier<T> qualifier, @Nullable Map<String,Object> argumentValues)
      Description copied from interface: BeanContext

      Creates a new instance of the given bean performing dependency injection and returning a new instance.

      If the bean defines any Parameter values then the values passed in the argumentValues parameter will be used

      Note that the instance returned is not saved as a singleton in the context.

      Specified by:
      createBean in interface BeanContext
      Type Parameters:
      T - The bean generic type
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      argumentValues - The argument values
      Returns:
      The instance
    • createBean

      public <T> @NonNull T createBean(@NonNull Class<T> beanType, @Nullable Qualifier<T> qualifier, @Nullable Object... args)
      Description copied from interface: BeanContext

      Creates a new instance of the given bean performing dependency injection and returning a new instance.

      If the bean defines any Parameter values then the values passed in the argumentValues parameter will be used

      Note that the instance returned is not saved as a singleton in the context.

      Specified by:
      createBean in interface BeanContext
      Type Parameters:
      T - The bean generic type
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      args - The argument values
      Returns:
      The instance
    • destroyBean

      public <T> @Nullable T destroyBean(@NonNull Argument<T> beanType, Qualifier<T> qualifier)
      Description copied from interface: BeanContext
      Destroys the bean for the given type causing it to be re-created. If a singleton has been loaded it will be destroyed and removed from the context, otherwise null will be returned.
      Specified by:
      destroyBean in interface BeanContext
      Type Parameters:
      T - The concrete class
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The destroy instance or null if no such bean exists
    • destroyBean

      public <T> @NonNull T destroyBean(@NonNull T bean)
      Description copied from interface: BeanContext
      Destroys the given bean.
      Specified by:
      destroyBean in interface BeanContext
      Type Parameters:
      T - The concrete class
      Parameters:
      bean - The bean
      Returns:
      The destroy instance
    • destroyBean

      public <T> @Nullable T destroyBean(@NonNull Class<T> beanType)
      Description copied from interface: BeanContext
      Destroys the bean for the given type causing it to be re-created. If a singleton has been loaded it will be destroyed and removed from the context, otherwise null will be returned.
      Specified by:
      destroyBean in interface BeanContext
      Type Parameters:
      T - The concrete class
      Parameters:
      beanType - The bean type
      Returns:
      The destroy instance or null if no such bean exists
    • destroyBean

      public <T> void destroyBean(@NonNull BeanRegistration<T> registration)
      Description copied from interface: BeanContext
      Destroys the given bean.
      Specified by:
      destroyBean in interface BeanContext
      Type Parameters:
      T - The bean type
      Parameters:
      registration - The bean registration
    • destroyLifeCycleBean

      @Internal protected <T> void destroyLifeCycleBean(LifeCycle<?> cycle, BeanDefinition<T> definition)
      Destroy a lifecycle bean.
      Type Parameters:
      T - The bean type
      Parameters:
      cycle - The cycle
      definition - The definition
    • getActiveBeanRegistration

      protected <T> @Nullable BeanRegistration<T> getActiveBeanRegistration(BeanDefinition<T> beanDefinition, Qualifier qualifier)
      Find an active singleton bean for the given definition and qualifier.
      Type Parameters:
      T - The bean generic type
      Parameters:
      beanDefinition - The bean definition
      qualifier - The qualifier
      Returns:
      The bean registration
    • createBean

      protected <T> @NonNull T createBean(@Nullable BeanResolutionContext resolutionContext, @NonNull Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Creates a bean.
      Type Parameters:
      T - The bean generic type
      Parameters:
      resolutionContext - The bean resolution context
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The instance
    • inject

      @Internal protected <T> @NonNull T inject(@NonNull BeanResolutionContext resolutionContext, @Nullable BeanDefinition<?> requestingBeanDefinition, @NonNull T instance)
      Injects a bean.
      Type Parameters:
      T - The instance type
      Parameters:
      resolutionContext - The bean resolution context
      requestingBeanDefinition - The requesting bean definition
      instance - The instance
      Returns:
      The instance
    • getBeansOfType

      protected <T> @NonNull Collection<T> getBeansOfType(@Nullable BeanResolutionContext resolutionContext, @NonNull Argument<T> beanType)
      Get all beans of the given type.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      resolutionContext - The bean resolution context
      beanType - The bean type
      Returns:
      The found beans
    • getBeansOfType

      @Internal public <T> @NonNull Collection<T> getBeansOfType(@Nullable BeanResolutionContext resolutionContext, @NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Get all beans of the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      resolutionContext - The bean resolution context
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The found beans
    • getProxyTargetBean

      public <T> @NonNull T getProxyTargetBean(@NonNull Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Resolves the proxy target for a given bean type. If the bean has no proxy then the original bean is returned.
      Specified by:
      getProxyTargetBean in interface BeanLocator
      Type Parameters:
      T - The generic type
      Parameters:
      beanType - The bean type
      qualifier - The bean qualifier
      Returns:
      The proxied instance
    • getProxyTargetBean

      public <T> @NonNull T getProxyTargetBean(@NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Resolves the proxy target for a given bean type. If the bean has no proxy then the original bean is returned.
      Specified by:
      getProxyTargetBean in interface BeanLocator
      Type Parameters:
      T - The generic type
      Parameters:
      beanType - The bean type
      qualifier - The bean qualifier
      Returns:
      The proxied instance
    • getProxyTargetBean

      public <T> @NonNull T getProxyTargetBean(@Nullable BeanResolutionContext resolutionContext, @NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Resolves the proxy target for a given bean type. If the bean has no proxy then the original bean is returned.
      Type Parameters:
      T - The generic type
      Parameters:
      resolutionContext - The bean resolution context
      beanType - The bean type
      qualifier - The bean qualifier
      Returns:
      The proxied instance
      Since:
      3.1.0
    • getProxyTargetBean

      @Internal public <T> @NonNull T getProxyTargetBean(@Nullable BeanResolutionContext resolutionContext, @NonNull BeanDefinition<T> definition, @NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Resolves the proxy target for a given proxy bean definition. If the bean has no proxy then the original bean is returned.
      Type Parameters:
      T - The generic type
      Parameters:
      resolutionContext - The bean resolution context
      definition - The proxy bean definition
      beanType - The bean type
      qualifier - The bean qualifier
      Returns:
      The proxied instance
      Since:
      4.3.0
    • findProxyTargetMethod

      public <T, R> @NonNull Optional<ExecutableMethod<T,R>> findProxyTargetMethod(@NonNull Class<T> beanType, @NonNull String method, @NonNull Class<?>[] arguments)
      Description copied from interface: ExecutionHandleLocator
      Finds the original unproxied method for a ProxyBeanDefinition.
      Specified by:
      findProxyTargetMethod in interface ExecutionHandleLocator
      Type Parameters:
      T - The bean type class
      R - The result type of the execution handle
      Parameters:
      beanType - The bean type
      method - The method
      arguments - The arguments
      Returns:
      The execution handle
    • findProxyTargetMethod

      public <T, R> @NonNull Optional<ExecutableMethod<T,R>> findProxyTargetMethod(@NonNull Class<T> beanType, Qualifier<T> qualifier, @NonNull String method, Class<?>... arguments)
      Description copied from interface: ExecutionHandleLocator
      Finds the original unproxied method for a ProxyBeanDefinition.
      Specified by:
      findProxyTargetMethod in interface ExecutionHandleLocator
      Type Parameters:
      T - The bean type class
      R - The result type of the execution handle
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      method - The method
      arguments - The arguments
      Returns:
      The execution handle
    • findProxyTargetMethod

      public <T, R> Optional<ExecutableMethod<T,R>> findProxyTargetMethod(@NonNull Argument<T> beanType, Qualifier<T> qualifier, @NonNull String method, Class<?>... arguments)
      Description copied from interface: ExecutionHandleLocator
      Finds the original unproxied method for a ProxyBeanDefinition.
      Specified by:
      findProxyTargetMethod in interface ExecutionHandleLocator
      Type Parameters:
      T - The bean type class
      R - The result type of the execution handle
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      method - The method
      arguments - The arguments
      Returns:
      The execution handle
    • findProxyTargetBeanDefinition

      public <T> @NonNull Optional<BeanDefinition<T>> findProxyTargetBeanDefinition(@NonNull Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanDefinitionRegistry
      Obtain the original BeanDefinition for a ProxyBeanDefinition.
      Specified by:
      findProxyTargetBeanDefinition in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The type
      qualifier - The qualifier
      Returns:
      An Optional of the bean definition
    • findProxyTargetBeanDefinition

      public <T> Optional<BeanDefinition<T>> findProxyTargetBeanDefinition(@NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanDefinitionRegistry
      Obtain the original BeanDefinition for a ProxyBeanDefinition.
      Specified by:
      findProxyTargetBeanDefinition in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The type
      qualifier - The qualifier
      Returns:
      An Optional of the bean definition
    • getBeanDefinitions

      public @NonNull Collection<BeanDefinition<Object>> getBeanDefinitions(@Nullable Qualifier<Object> qualifier)
      Description copied from interface: BeanDefinitionRegistry
      Get all of the BeanDefinition for the given qualifier.
      Specified by:
      getBeanDefinitions in interface BeanDefinitionRegistry
      Parameters:
      qualifier - The qualifier
      Returns:
      The bean definitions
    • getAllBeanDefinitions

      public @NonNull Collection<BeanDefinition<Object>> getAllBeanDefinitions()
      Description copied from interface: BeanDefinitionRegistry
      Get all registered BeanDefinition.
      Specified by:
      getAllBeanDefinitions in interface BeanDefinitionRegistry
      Returns:
      The bean definitions
    • getDisabledBeans

      public Collection<DisabledBean<?>> getDisabledBeans()
      Description copied from interface: BeanDefinitionRegistry
      Get all disabled DisabledBean.
      Specified by:
      getDisabledBeans in interface BeanDefinitionRegistry
      Returns:
      The disabled bean definitions
    • getBeanDefinitionReferences

      public @NonNull Collection<BeanDefinitionReference<Object>> getBeanDefinitionReferences()
      Description copied from interface: BeanDefinitionRegistry
      Get all enabled BeanDefinitionReference.
      Specified by:
      getBeanDefinitionReferences in interface BeanDefinitionRegistry
      Returns:
      The bean definitions
    • registerBeanConfiguration

      public BeanContext registerBeanConfiguration(BeanConfiguration configuration)
      Description copied from interface: BeanDefinitionRegistry
      Registers a bean configuration. This allows disabling a set of beans based on a condition.
      Specified by:
      registerBeanConfiguration in interface BeanDefinitionRegistry
      Parameters:
      configuration - The configuration
      Returns:
      The registry
    • registerBeanDefinition

      public <B> @NonNull BeanContext registerBeanDefinition(@NonNull RuntimeBeanDefinition<B> definition)
      Description copied from interface: BeanDefinitionRegistry
      Registers a new reference at runtime. Not that registering beans can impact the object graph therefore should this should be done as soon as possible prior to the creation of other beans preferably with a high priority Context scope bean.
      Specified by:
      registerBeanDefinition in interface BeanDefinitionRegistry
      Type Parameters:
      B - The bean type
      Parameters:
      definition - The reference.
      Returns:
      The registry
    • getBean

      public <T> @NonNull T getBean(@Nullable BeanResolutionContext resolutionContext, @NonNull Class<T> beanType)
      Get a bean of the given type.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      resolutionContext - The bean context resolution
      beanType - The bean type
      Returns:
      The found bean
    • getBean

      public <T> @NonNull T getBean(@NonNull BeanDefinition<T> definition)
      Description copied from interface: BeanLocator
      Obtains a Bean for the given bean definition.
      Specified by:
      getBean in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      definition - The bean type
      Returns:
      An instanceof said bean
      See Also:
    • getBean

      public <T> @NonNull T getBean(@Nullable BeanResolutionContext resolutionContext, @NonNull Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Get a bean of the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      resolutionContext - The bean context resolution
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The found bean
    • getBean

      public <T> @NonNull T getBean(@Nullable BeanResolutionContext resolutionContext, @NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Get a bean of the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      resolutionContext - The bean context resolution
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The found bean
      Since:
      3.0.0
    • getBean

      @Internal public <T> @NonNull T getBean(@Nullable BeanResolutionContext resolutionContext, @NonNull BeanDefinition<T> beanDefinition, @NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Get a bean of the given bean definition, type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      resolutionContext - The bean context resolution
      beanDefinition - The bean definition
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The found bean
      Since:
      3.5.0
    • findBean

      public <T> @NonNull Optional<T> findBean(@Nullable BeanResolutionContext resolutionContext, @NonNull Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Find an optional bean of the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      resolutionContext - The bean context resolution
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The found bean wrapped as an Optional
    • findBean

      @Internal public <T> @NonNull Optional<T> findBean(@Nullable BeanResolutionContext resolutionContext, @NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Find an optional bean of the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      resolutionContext - The bean context resolution
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The found bean wrapped as an Optional
      Since:
      3.0.0
    • getContextConfiguration

      public BeanContextConfiguration getContextConfiguration()
      Description copied from interface: BeanContext
      Obtains the configuration for this context.
      Specified by:
      getContextConfiguration in interface BeanContext
      Returns:
      The BeanContextConfiguration
    • publishEvent

      public void publishEvent(@NonNull Object event)
      Description copied from interface: ApplicationEventPublisher
      Publish the given event. The event will be published synchronously and only return once all listeners have consumed the event.
      Specified by:
      publishEvent in interface ApplicationEventPublisher<Object>
      Parameters:
      event - The event to publish
    • publishEventAsync

      public @NonNull Future<Void> publishEventAsync(@NonNull Object event)
      Description copied from interface: ApplicationEventPublisher
      Publish the given event. The event will be published asynchronously. A future is returned that can be used to check whether the event completed successfully or not.
      Specified by:
      publishEventAsync in interface ApplicationEventPublisher<Object>
      Parameters:
      event - The event to publish
      Returns:
      A future that completes when the event is published
    • findProxyBeanDefinition

      public <T> @NonNull Optional<BeanDefinition<T>> findProxyBeanDefinition(@NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanDefinitionRegistry
      Obtain the proxy BeanDefinition for the bean of type and qualifier.
      Specified by:
      findProxyBeanDefinition in interface BeanDefinitionRegistry
      Type Parameters:
      T - The concrete type
      Parameters:
      beanType - The type
      qualifier - The qualifier
      Returns:
      An Optional of the bean definition
    • invalidateCaches

      @Internal protected void invalidateCaches()
      Invalidates the bean caches. For testing only.
    • resolveBeanConfigurations

      protected @NonNull Iterable<BeanConfiguration> resolveBeanConfigurations()
      Resolves the BeanConfiguration class instances. Default implementation uses ServiceLoader pattern.
      Returns:
      The bean definition classes
    • findBeanCandidates

      @Internal public final <T> @NonNull Collection<BeanDefinition<T>> findBeanCandidates(@Nullable BeanResolutionContext resolutionContext, @NonNull Argument<T> beanType, @Nullable BeanDefinition<?> filter)
      Find bean candidates for the given type.
      Type Parameters:
      T - The bean generic type
      Parameters:
      resolutionContext - The current resolution context
      beanType - The bean type
      filter - A bean definition to filter out
      Returns:
      The candidates
    • findBeanCandidates

      protected <T> @NonNull Collection<BeanDefinition<T>> findBeanCandidates(@Nullable BeanResolutionContext resolutionContext, @NonNull Argument<T> beanType, boolean collectIterables, Predicate<BeanDefinition<T>> predicate)
      Find bean candidates for the given type.
      Type Parameters:
      T - The bean generic type
      Parameters:
      resolutionContext - The current resolution context
      beanType - The bean type
      collectIterables - Whether iterables should be collected
      predicate - The predicate to filter candidates
      Returns:
      The candidates
    • collectIterableBeans

      protected <T> void collectIterableBeans(@Nullable BeanResolutionContext resolutionContext, @NonNull BeanDefinition<T> iterableBean, @NonNull Set<BeanDefinition<T>> targetSet, @NonNull Argument<T> beanType)
      Collects iterable beans from a given iterable.
      Type Parameters:
      T - The bean type
      Parameters:
      resolutionContext - The resolution context
      iterableBean - The iterable
      targetSet - The target set
      beanType - The bean type
    • findBeanCandidatesForInstance

      protected <T> @NonNull Collection<BeanDefinition<T>> findBeanCandidatesForInstance(@NonNull T instance)
      Find bean candidates for the given type.
      Type Parameters:
      T - The bean generic type
      Parameters:
      instance - The bean instance
      Returns:
      The candidates
    • registerConfiguration

      protected void registerConfiguration(@NonNull BeanConfiguration configuration)
      Registers an active configuration.
      Parameters:
      configuration - The configuration to register
    • findConcreteCandidate

      protected <T> @NonNull BeanDefinition<T> findConcreteCandidate(@NonNull Class<T> beanType, @Nullable Qualifier<T> qualifier, @NonNull Collection<BeanDefinition<T>> candidates)
      Fall back method to attempt to find a candidate for the given definitions.
      Type Parameters:
      T - The generic time
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      candidates - The candidates, always more than 1
      Returns:
      The concrete bean definition
    • newNoSuchBeanException

      @Internal protected <T> @NonNull NoSuchBeanException newNoSuchBeanException(@Nullable BeanResolutionContext resolutionContext, @NonNull Argument<T> beanType, @NonNull Qualifier<T> qualifier, @Nullable String message)
      Trigger a no such bean exception. Subclasses can improve the exception with downstream diagnosis as necessary.
      Type Parameters:
      T - The type of the bean
      Parameters:
      resolutionContext - The resolution context
      beanType - The bean type
      qualifier - The qualifier
      message - A message to use
      Returns:
      A no such bean exception
    • resolveDisabledBeanMessage

      protected <T> @Nullable String resolveDisabledBeanMessage(BeanResolutionContext resolutionContext, Argument<T> beanType, Qualifier<T> qualifier)
      Resolves the message to use for a disabled bean.
      Type Parameters:
      T - The bean type
      Parameters:
      resolutionContext - The resolution context
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The message or null if none exists
    • initializeTypeConverters

      protected void initializeTypeConverters()
    • getBeanRegistration

      @Internal public <T> BeanRegistration<T> getBeanRegistration(@Nullable BeanResolutionContext resolutionContext, @NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Obtains the bean registration for the given type and qualifier.
      Type Parameters:
      T - The generic type
      Parameters:
      resolutionContext - The resolution context
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      A BeanRegistration
    • getBeanRegistrations

      @Internal public <T> Collection<BeanRegistration<T>> getBeanRegistrations(@Nullable BeanResolutionContext resolutionContext, @NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Obtains the bean registrations for the given type and qualifier.
      Type Parameters:
      T - The generic type
      Parameters:
      resolutionContext - The resolution context
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      A collection of BeanRegistration
    • getAttributes

      public @NonNull MutableConvertibleValues<Object> getAttributes()
      Description copied from interface: MutableAttributeHolder
      Overrides the default AttributeHolder.getAttributes() method to return a mutable object.
      Specified by:
      getAttributes in interface AttributeHolder
      Specified by:
      getAttributes in interface MutableAttributeHolder
      Returns:
      The mutable attributes
    • getAttribute

      public @NonNull Optional<Object> getAttribute(CharSequence name)
      Description copied from interface: AttributeHolder
      Obtain the value of an attribute on the HTTP method.
      Specified by:
      getAttribute in interface AttributeHolder
      Parameters:
      name - The name of the attribute
      Returns:
      An Optional value
    • getAttribute

      public <T> @NonNull Optional<T> getAttribute(CharSequence name, Class<T> type)
      Description copied from interface: AttributeHolder
      Obtain the value of an attribute on the HTTP method.
      Specified by:
      getAttribute in interface AttributeHolder
      Type Parameters:
      T - type Generic
      Parameters:
      name - The name of the attribute
      type - The required type
      Returns:
      An Optional value
    • setAttribute

      public @NonNull BeanContext setAttribute(@NonNull CharSequence name, @Nullable Object value)
      Description copied from interface: MutableAttributeHolder
      Sets an attribute on the message.
      Specified by:
      setAttribute in interface MutableAttributeHolder
      Parameters:
      name - The name of the attribute
      value - The value of the attribute
      Returns:
      This message
    • removeAttribute

      public <T> @NonNull Optional<T> removeAttribute(@NonNull CharSequence name, @NonNull Class<T> type)
      Description copied from interface: MutableAttributeHolder
      Remove an attribute. Returning the old value if it is present.
      Specified by:
      removeAttribute in interface MutableAttributeHolder
      Type Parameters:
      T - type Generic
      Parameters:
      name - The name of the attribute
      type - The required type
      Returns:
      An Optional value
    • getConversionService

      public MutableConversionService getConversionService()
      Description copied from interface: ConversionServiceProvider
      Provides the conversion service.
      Specified by:
      getConversionService in interface ConversionServiceProvider
      Returns:
      the conversion service
    • configure

      public final void configure()
      Description copied from interface: ConfigurableBeanContext
      Configures the bean context loading all bean definitions required to perform successful startup without starting the context itself.

      Once called the methods of the BeanDefinitionRegistry interface will return results allowing inspection of the context without needing to run the context.

      Specified by:
      configure in interface ConfigurableBeanContext
      See Also: