public interface BeanContext extends LifeCycle<BeanContext>, ExecutionHandleLocator, BeanLocator, BeanDefinitionRegistry, ApplicationEventPublisher<Object>, 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
NO_OP
DEFAULT
Modifier and Type | Method and Description |
---|---|
static BeanContext |
build()
Build a
BeanContext . |
static BeanContext |
build(ClassLoader classLoader)
Build a
BeanContext . |
default <T> T |
createBean(Class<T> beanType)
Creates a new instance of the given bean performing dependency injection and returning a new instance.
|
default <T> T |
createBean(Class<T> beanType,
Map<String,Object> argumentValues)
Creates a new instance of the given bean performing dependency injection and returning a new instance.
|
default <T> T |
createBean(Class<T> beanType,
Object... args)
Creates a new instance of the given bean performing dependency injection and returning a new instance.
|
<T> T |
createBean(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(Class<T> beanType,
Qualifier<T> qualifier,
Map<String,Object> argumentValues)
Creates a new instance of the given bean performing dependency injection and returning a new instance.
|
<T> T |
createBean(Class<T> beanType,
Qualifier<T> qualifier,
Object... args)
Creates a new instance of the given bean performing dependency injection and returning a new instance.
|
default <T> T |
destroyBean(Argument<T> beanType)
Destroys the bean for the given type causing it to be re-created.
|
<T> T |
destroyBean(Argument<T> beanType,
Qualifier<T> qualifier)
Destroys the bean for the given type causing it to be re-created.
|
<T> T |
destroyBean(Class<T> beanType)
Destroys the bean for the given type causing it to be re-created.
|
<T> T |
destroyBean(T bean)
Destroys the given bean.
|
BeanDefinitionValidator |
getBeanValidator() |
ClassLoader |
getClassLoader() |
BeanContextConfiguration |
getContextConfiguration()
Obtains the configuration for this context.
|
default <E> ApplicationEventPublisher<E> |
getEventPublisher(Class<E> eventType)
Obtain an
ApplicationEventPublisher for the given even type. |
<T> T |
inject(T instance)
Inject an existing instance.
|
void |
publishEvent(Object event)
Deprecated.
Preferred way is to use event typed
ApplicationEventPublisher<MyEventType> |
default Future<Void> |
publishEventAsync(Object event)
Deprecated.
Preferred way is to use event typed
ApplicationEventPublisher<MyEventType> |
<T> Optional<T> |
refreshBean(BeanIdentifier identifier)
Refresh the state of the given registered bean applying dependency injection and configuration wiring again.
|
default <T> BeanContext |
registerSingleton(Class<T> type,
T singleton)
Registers a new singleton bean at runtime.
|
default <T> BeanContext |
registerSingleton(Class<T> type,
T singleton,
Qualifier<T> qualifier)
Registers a new singleton bean at runtime.
|
<T> BeanContext |
registerSingleton(Class<T> type,
T singleton,
Qualifier<T> qualifier,
boolean inject)
Registers a new singleton bean at runtime.
|
default BeanContext |
registerSingleton(Object singleton)
Registers a new singleton bean at runtime.
|
default BeanContext |
registerSingleton(Object singleton,
boolean inject)
Registers a new singleton bean at runtime.
|
static BeanContext |
run()
Run the
BeanContext . |
static BeanContext |
run(ClassLoader classLoader)
Run the
BeanContext . |
close, isRunning, refresh, start, stop
createExecutionHandle, findExecutableMethod, findExecutionHandle, findExecutionHandle, findExecutionHandle, findProxyTargetMethod, findProxyTargetMethod, findProxyTargetMethod, getExecutableMethod, getExecutionHandle, getExecutionHandle, getProxyTargetMethod, getProxyTargetMethod, getProxyTargetMethod
findBean, findBean, findBean, findBean, findOrInstantiateBean, getBean, getBean, getBean, getBean, getBean, getBeansOfType, getBeansOfType, getBeansOfType, getBeansOfType, getProxyTargetBean, getProxyTargetBean, streamOfType, streamOfType, streamOfType, streamOfType
containsBean, containsBean, containsBean, containsBean, findBeanConfiguration, findBeanDefinition, findBeanDefinition, findBeanDefinition, findBeanDefinition, findBeanRegistration, findProxyBeanDefinition, findProxyBeanDefinition, findProxyTargetBeanDefinition, findProxyTargetBeanDefinition, getActiveBeanRegistrations, getActiveBeanRegistrations, getAllBeanDefinitions, getBeanDefinition, getBeanDefinition, getBeanDefinition, getBeanDefinition, getBeanDefinitionReferences, getBeanDefinitions, getBeanDefinitions, getBeanDefinitions, getBeanDefinitions, getBeanDefinitions, getBeanRegistration, getBeanRegistration, getBeanRegistrations, getBeanRegistrations, getBeanRegistrations, getProxyTargetBeanDefinition, getProxyTargetBeanDefinition
noOp
resolveMetadata, resolveMetadata
getAttributes, removeAttribute, setAttribute
getAttribute, getAttribute
@NonNull BeanContextConfiguration getContextConfiguration()
BeanContextConfiguration
@NonNull default <E> ApplicationEventPublisher<E> getEventPublisher(@NonNull Class<E> eventType)
ApplicationEventPublisher
for the given even type.E
- The event generic typeeventType
- The event typenull
@Deprecated void publishEvent(Object event)
ApplicationEventPublisher<MyEventType>
publishEvent
in interface ApplicationEventPublisher<Object>
event
- The event to publish@Deprecated default Future<Void> publishEventAsync(Object event)
ApplicationEventPublisher<MyEventType>
publishEventAsync
in interface ApplicationEventPublisher<Object>
event
- The event to publish@NonNull <T> T inject(@NonNull T instance)
T
- The bean generic typeinstance
- The instance to inject@NonNull default <T> T createBean(@NonNull 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 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 Class<T> beanType, @Nullable Qualifier<T> qualifier, @Nullable Map<String,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 Class<T> beanType, @Nullable Qualifier<T> qualifier, @Nullable 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 Class<T> beanType, @Nullable 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 Class<T> beanType, @Nullable Map<String,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 Class<T> beanType)
T
- The concrete classbeanType
- The bean type@Nullable default <T> T destroyBean(@NonNull Argument<T> beanType)
T
- The concrete classbeanType
- The bean type@Nullable <T> T destroyBean(@NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier)
T
- The concrete classbeanType
- The bean typequalifier
- The qualifier@NonNull <T> T destroyBean(@NonNull T bean)
T
- The concrete classbean
- The bean@NonNull <T> 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 ClassLoader getClassLoader()
@NonNull BeanDefinitionValidator getBeanValidator()
@NonNull <T> BeanContext registerSingleton(@NonNull 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 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(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(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@NonNull default BeanContext registerSingleton(@NonNull 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(ClassLoader classLoader)
classLoader
- The classloader to useBeanContext
@NonNull static BeanContext build(ClassLoader classLoader)
BeanContext
.classLoader
- The classloader to useBeanContext