Package io.smallrye.beanbag
Class BeanBag
- java.lang.Object
-
- io.smallrye.beanbag.BeanBag
-
public final class BeanBag extends Object
A basic bean container.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBeanBag.BeanBuilder<T>A builder for an individual bean's configuration.static classBeanBag.BuilderA builder for a new container.static classBeanBag.SupplierBuilder<T>A builder for a bean supplier which constructs a bean using reflection.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static 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.ScopenewScope()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 Detail
-
newScope
public Scope newScope()
Create a new resolution scope. A resolution scope maintains independent instances of its beans.- Returns:
- the new resolution scope (not
null)
-
getAllBeans
public <T> List<T> getAllBeans(Class<T> type)
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
public <T> T requireBean(Class<T> type)
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
public <T> T requireBean(Class<T> type, String name)
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
public <T> T getOptionalBean(Class<T> type)
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
public <T> T getOptionalBean(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.- 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
public static BeanBag.Builder builder()
Construct a new container builder.- Returns:
- the new builder (not
null)
-
-