public interface BeanContext extends LifeCycle<BeanContext>, ExecutionHandleLocator, BeanLocator, BeanDefinitionRegistry, ApplicationEventPublisher, AnnotationMetadataResolver
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.
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.
|
<T> T |
destroyBean(Class<T> beanType)
Destroys the bean for the given type causing it to be re-created.
|
ClassLoader |
getClassLoader() |
<T> T |
inject(T instance)
Inject an existing instance.
|
<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
findExecutableMethod, findExecutionHandle, findExecutionHandle, findExecutionHandle, findProxyTargetMethod, getExecutableMethod, getExecutionHandle, getExecutionHandle, getProxyTargetMethod
findBean, findBean, findOrInstantiateBean, 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
resolveMetadata, resolveMetadata
@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@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 <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@NotNull default BeanContext registerSingleton(@NotNull 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