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.
EMPTYNO_OPDEFAULT| 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, stopcreateExecutionHandle, findExecutableMethod, findExecutionHandle, findExecutionHandle, findExecutionHandle, findProxyTargetMethod, findProxyTargetMethod, findProxyTargetMethod, getExecutableMethod, getExecutionHandle, getExecutionHandle, getProxyTargetMethod, getProxyTargetMethod, getProxyTargetMethodfindBean, findBean, findBean, findBean, findOrInstantiateBean, getBean, getBean, getBean, getBean, getBean, getBeansOfType, getBeansOfType, getBeansOfType, getBeansOfType, getProxyTargetBean, getProxyTargetBean, streamOfType, streamOfType, streamOfType, streamOfTypecontainsBean, 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, getProxyTargetBeanDefinitionnoOpresolveMetadata, resolveMetadatagetAttributes, removeAttribute, setAttributegetAttribute, 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 BeanIdentifierOptional 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)
BeanDefinitionRegistryRegisters 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 BeanDefinitionRegistryT - 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)
BeanDefinitionRegistryRegisters 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 BeanDefinitionRegistrysingleton - The singleton beandefault <T> BeanContext registerSingleton(Class<T> type, T singleton, Qualifier<T> qualifier)
BeanDefinitionRegistryRegisters 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 BeanDefinitionRegistryT - The concrete typetype - The bean typesingleton - The singleton beanqualifier - The bean qualifierdefault <T> BeanContext registerSingleton(Class<T> type, T singleton)
BeanDefinitionRegistryRegisters 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 BeanDefinitionRegistryT - The concrete typetype - the bean typesingleton - The singleton bean@NonNull default BeanContext registerSingleton(@NonNull Object singleton, boolean inject)
BeanDefinitionRegistryRegisters 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 BeanDefinitionRegistrysingleton - 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