Package io.smallrye.beanbag
Class Scope
- java.lang.Object
-
- io.smallrye.beanbag.Scope
-
public final class Scope extends Object
A (potentially nested) scope from which bean instances may be acquired.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> List<T>getAllBeans(Class<T> type)Get all constructable beans of the given type.<T> List<T>getAllBeans(Class<T> type, DependencyFilter filter)Get all constructable beans of the given type.<T> List<T>getAllBeans(Class<T> type, String name)Get all constructable beans of the given type and name.<T> List<T>getAllBeans(Class<T> type, String name, DependencyFilter filter)Get all constructable beans of the given type and name.<T> Map<String,T>getAllBeansWithNames(Class<T> type, DependencyFilter filter)Get all constructable beans of the given type as a map.<T> TgetBean(Class<T> type, String name, boolean optional, DependencyFilter filter)Get a single bean with the given type and name, with configurable optionality.BeanBaggetContainer()<T> TgetOptionalBean(Class<T> type)Get a single bean with the given type, if it exists and can be instantiated.<T> TgetOptionalBean(Class<T> type, String name)Get a single bean with the given type and name, if it exists and can be instantiated.<T> TgetOptionalBean(Class<T> type, String name, DependencyFilter filter)Get a single bean with the given type and name, if it exists and can be instantiated.<T> TrequireBean(Class<T> type)Require a single bean with the given type.<T> TrequireBean(Class<T> type, String name)Require a single bean with the given type and name.
-
-
-
Method Detail
-
getAllBeans
public <T> List<T> getAllBeans(Class<T> type)
Get all constructable beans of the given type.- 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
-
getAllBeans
public <T> List<T> getAllBeans(Class<T> type, DependencyFilter filter)
Get all constructable beans of the given type. The filter is applied to each bean to determine whether it should be instantiated.- Type Parameters:
T- the allowed bean type- Parameters:
type- the allowed bean type class (must not benull)filter- the filter to apply to determine whether a given bean should be included (must not benull)- Returns:
- the (possibly empty) list of all matching beans
-
getAllBeans
public <T> List<T> getAllBeans(Class<T> type, String name)
Get all constructable beans of the given type and name.- 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 (possibly empty) list of all matching beans
-
getAllBeans
public <T> List<T> getAllBeans(Class<T> type, String name, DependencyFilter filter)
Get all constructable beans of the given type and name. The filter is applied to each bean to determine whether it should 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)filter- the filter to apply to determine whether a given bean should be included (must not benull)- Returns:
- the (possibly empty) list of all matching beans
-
getAllBeansWithNames
public <T> Map<String,T> getAllBeansWithNames(Class<T> type, DependencyFilter filter)
Get all constructable beans of the given type as a map. The filter is applied to each bean to determine whether it should be instantiated.- Type Parameters:
T- the allowed bean type- Parameters:
type- the allowed bean type class (must not benull)filter- the filter to apply to determine whether a given bean should be included (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.- 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.- 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, 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, 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
-
getOptionalBean
public <T> T getOptionalBean(Class<T> type, String name, DependencyFilter filter)
Get a single bean with the given type and name, if it exists and can be instantiated. The filter is applied to each bean to determine whether it should 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)filter- the filter to apply to determine whether a given bean should be included (must not benull)- Returns:
- the single bean, or
nullif it is not present
-
getBean
public <T> T getBean(Class<T> type, String name, boolean optional, DependencyFilter filter)
Get a single bean with the given type and name, with configurable optionality. The filter is applied to each bean to determine whether it should 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)optional-trueto return null if no bean matches, orfalseto throw an exception if no bean matchesfilter- the filter to apply to determine whether a given bean should be included (must not benull)- Returns:
- the single bean, or
nullif it is not present - Throws:
NoSuchBeanException- if the bean is not present
-
getContainer
public BeanBag getContainer()
-
-