public interface BeanContext extends LifeCycle<BeanContext>, ExecutionHandleLocator, BeanLocator, BeanDefinitionRegistry, ApplicationEventPublisher, AnnotationMetadataResolver, MutableAttributeHolder
The core BeanContext abstraction which allows for dependency injection of classes annotated with
Inject
.
Apart of the standard javax.inject
annotations for dependency injection, additional annotations within
the io.micronaut.context.annotation
package allow control over configuration of the bean context.
EMPTY
DEFAULT
Modifier and Type | Method and Description |
---|---|
static BeanContext |
build()
Build a
BeanContext . |
static BeanContext |
build(java.lang.ClassLoader classLoader)
Build a
BeanContext . |
default <T> T |
createBean(java.lang.Class<T> beanType)
Creates a new instance of the given bean performing dependency injection and returning a new instance.
|
default <T> T |
createBean(java.lang.Class<T> beanType,
java.util.Map<java.lang.String,java.lang.Object> argumentValues)
Creates a new instance of the given bean performing dependency injection and returning a new instance.
|
default <T> T |
createBean(java.lang.Class<T> beanType,
java.lang.Object... args)
Creates a new instance of the given bean performing dependency injection and returning a new instance.
|
<T> T |
createBean(java.lang.Class<T> beanType,
Qualifier<T> qualifier)
Creates a new instance of the given bean performing dependency injection and returning a new instance.
|
<T> T |
createBean(java.lang.Class<T> beanType,
Qualifier<T> qualifier,
java.util.Map<java.lang.String,java.lang.Object> argumentValues)
Creates a new instance of the given bean performing dependency injection and returning a new instance.
|
<T> T |
createBean(java.lang.Class<T> beanType,
Qualifier<T> qualifier,
java.lang.Object... args)
Creates a new instance of the given bean performing dependency injection and returning a new instance.
|
<T> T |
destroyBean(java.lang.Class<T> beanType)
Destroys the bean for the given type causing it to be re-created.
|
BeanDefinitionValidator |
getBeanValidator() |
java.lang.ClassLoader |
getClassLoader() |
<T> T |
inject(T instance)
Inject an existing instance.
|
<T> java.util.Optional<T> |
refreshBean(BeanIdentifier identifier)
Refresh the state of the given registered bean applying dependency injection and configuration wiring again.
|
default <T> BeanContext |
registerSingleton(java.lang.Class<T> type,
T singleton)
Registers a new singleton bean at runtime.
|
default <T> BeanContext |
registerSingleton(java.lang.Class<T> type,
T singleton,
Qualifier<T> qualifier)
Registers a new singleton bean at runtime.
|
<T> BeanContext |
registerSingleton(java.lang.Class<T> type,
T singleton,
Qualifier<T> qualifier,
boolean inject)
Registers a new singleton bean at runtime.
|
default BeanContext |
registerSingleton(java.lang.Object singleton)
Registers a new singleton bean at runtime.
|
default @NotNull BeanContext |
registerSingleton(@NotNull java.lang.Object singleton,
boolean inject)
Registers a new singleton bean at runtime.
|
static BeanContext |
run()
Run the
BeanContext . |
static BeanContext |
run(java.lang.ClassLoader classLoader)
Run the
BeanContext . |
close, isRunning, refresh, start, stop
createExecutionHandle, findExecutableMethod, findExecutionHandle, findExecutionHandle, findExecutionHandle, findProxyTargetMethod, findProxyTargetMethod, getExecutableMethod, getExecutionHandle, getExecutionHandle, getProxyTargetMethod, getProxyTargetMethod
findBean, findBean, findOrInstantiateBean, getBean, getBean, getBean, getBeansOfType, getBeansOfType, getProxyTargetBean, streamOfType, streamOfType
containsBean, containsBean, findBeanConfiguration, findBeanDefinition, findBeanDefinition, findBeanRegistration, findProxyBeanDefinition, findProxyTargetBeanDefinition, getActiveBeanRegistrations, getActiveBeanRegistrations, getAllBeanDefinitions, getBeanDefinition, getBeanDefinition, getBeanDefinitionReferences, getBeanDefinitions, getBeanDefinitions, getBeanDefinitions, getBeanRegistrations, getProxyTargetBeanDefinition
publishEvent, publishEventAsync
resolveMetadata, resolveMetadata
getAttributes, removeAttribute, setAttribute
getAttribute, getAttribute
@NonNull <T> T inject(@NonNull T instance)
T
- The bean generic typeinstance
- The instance to inject@NonNull default <T> T createBean(@NonNull java.lang.Class<T> beanType)
Note that the instance returned is not saved as a singleton in the context.
T
- The bean generic typebeanType
- The bean type@NonNull <T> T createBean(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Note that the instance returned is not saved as a singleton in the context.
T
- The bean generic typebeanType
- The bean typequalifier
- The qualifier@NonNull <T> T createBean(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier, @Nullable java.util.Map<java.lang.String,java.lang.Object> argumentValues)
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.
T
- The bean generic typebeanType
- The bean typequalifier
- The qualifierargumentValues
- The argument values@NonNull <T> T createBean(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier, @Nullable java.lang.Object... args)
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.
T
- The bean generic typebeanType
- The bean typequalifier
- The qualifierargs
- The argument values@NonNull default <T> T createBean(@NonNull java.lang.Class<T> beanType, @Nullable java.lang.Object... args)
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.
T
- The bean generic typebeanType
- The bean typeargs
- The argument values@NonNull default <T> T createBean(@NonNull java.lang.Class<T> beanType, @Nullable java.util.Map<java.lang.String,java.lang.Object> argumentValues)
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.
T
- The bean generic typebeanType
- The bean typeargumentValues
- The argument values@Nullable <T> T destroyBean(@NonNull java.lang.Class<T> beanType)
T
- The concrete classbeanType
- The bean type@NonNull <T> java.util.Optional<T> refreshBean(@Nullable BeanIdentifier identifier)
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
T
- The concrete classidentifier
- The BeanIdentifier
Optional
of the instance if it exists for the given registration@NonNull java.lang.ClassLoader getClassLoader()
@NonNull BeanDefinitionValidator getBeanValidator()
@NonNull <T> BeanContext registerSingleton(@NonNull java.lang.Class<T> type, @NonNull T singleton, @Nullable Qualifier<T> qualifier, boolean inject)
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.
registerSingleton
in interface BeanDefinitionRegistry
T
- The concrete typetype
- The bean typesingleton
- The singleton beanqualifier
- The bean qualifierinject
- Whether the singleton should be injected (defaults to true)default BeanContext registerSingleton(@NonNull java.lang.Object singleton)
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.
registerSingleton
in interface BeanDefinitionRegistry
singleton
- The singleton beandefault <T> BeanContext registerSingleton(java.lang.Class<T> type, T singleton, Qualifier<T> qualifier)
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.
registerSingleton
in interface BeanDefinitionRegistry
T
- The concrete typetype
- The bean typesingleton
- The singleton beanqualifier
- The bean qualifierdefault <T> BeanContext registerSingleton(java.lang.Class<T> type, T singleton)
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.
registerSingleton
in interface BeanDefinitionRegistry
T
- The concrete typetype
- the bean typesingleton
- The singleton bean@NotNull default @NotNull BeanContext registerSingleton(@NotNull @NotNull java.lang.Object singleton, boolean inject)
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.
registerSingleton
in interface BeanDefinitionRegistry
singleton
- The singleton beaninject
- Whether the singleton should be injected (defaults to true)@NonNull static BeanContext run()
BeanContext
@NonNull static BeanContext build()
BeanContext
.BeanContext
@NonNull static BeanContext run(java.lang.ClassLoader classLoader)
classLoader
- The classloader to useBeanContext
@NonNull static BeanContext build(java.lang.ClassLoader classLoader)
BeanContext
.classLoader
- The classloader to useBeanContext