Package io.smallrye.beanbag
Class BeanBag
java.lang.Object
io.smallrye.beanbag.BeanBag
A basic bean container.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA builder for an individual bean's configuration.static final classA builder for a new container.static final classA builder for a bean supplier which constructs a bean using reflection. -
Method Summary
Modifier and TypeMethodDescriptionstatic BeanBag.Builderbuilder()Construct a new container builder.<T> List<T>getAllBeans(Class<T> type) Get all constructable beans of the given type from a new resolution scope.<T> TgetOptionalBean(Class<T> type) Get a single bean with the given type from a new resolution scope, if it exists and can be instantiated.<T> TgetOptionalBean(Class<T> type, String name) Get a single bean with the given type and name from a new resolution scope, if it exists and can be instantiated.newScope()Create a new resolution scope.<T> TrequireBean(Class<T> type) Require a single bean with the given type from a new resolution scope.<T> TrequireBean(Class<T> type, String name) Require a single bean with the given type and name from a new resolution scope.
-
Method Details
-
newScope
Create a new resolution scope. A resolution scope maintains independent instances of its beans.- Returns:
- the new resolution scope (not
null)
-
getAllBeans
Get all constructable beans of the given type from a new resolution scope.- Type Parameters:
T- the allowed bean type- Parameters:
type- the allowed bean type class (must not benull)- Returns:
- the (possibly empty) list of all matching beans
-
requireBean
Require a single bean with the given type from a new resolution scope.- Type Parameters:
T- the allowed bean type- Parameters:
type- the allowed bean type class (must not benull)- Returns:
- the single bean (not
null) - Throws:
NoSuchBeanException- if the bean is not presentBeanInstantiationException- if some error occurred when instantiating the bean
-
requireBean
Require a single bean with the given type and name from a new resolution scope.- Type Parameters:
T- the allowed bean type- Parameters:
type- the allowed bean type class (must not benull)name- the name of the bean which should be returned, or""for any (must not benull)- Returns:
- the single bean (not
null) - Throws:
NoSuchBeanException- if the bean is not presentBeanInstantiationException- if some error occurred when instantiating the bean
-
getOptionalBean
Get a single bean with the given type from a new resolution scope, if it exists and can be instantiated.- Type Parameters:
T- the allowed bean type- Parameters:
type- the allowed bean type class (must not benull)- Returns:
- the single bean, or
nullif it is not present
-
getOptionalBean
Get a single bean with the given type and name from a new resolution scope, if it exists and can be instantiated.- Type Parameters:
T- the allowed bean type- Parameters:
type- the allowed bean type class (must not benull)name- the name of the bean which should be returned, or""for any (must not benull)- Returns:
- the single bean, or
nullif it is not present
-
builder
Construct a new container builder.- Returns:
- the new builder (not
null)
-