Package io.avaje.inject
Class SystemContext
- java.lang.Object
-
- io.avaje.inject.SystemContext
-
public class SystemContext extends Object
Provides a global system wide BeanContext that contains all the bean contexts in the classpath.This will automatically get all the bean contexts and wire them all as necessary. It will use a shutdown hook to fire any
@PreDestroymethods on beans.Example: get a bean
CoffeeMaker coffeeMaker = SystemContext.getBean(CoffeeMaker.class); coffeeMaker.brew();Example: get all the beans implementing an interface
// e.g. register all WebRoutes for a web framework List<WebRoute> routes = SystemContext.getBeans(WebRoute.class); // register all the routes ...Example: get all the beans that have an annotation
// e.g. register all controllers with web a framework // .. where Controller is an annotation on the beans List<Object> controllers = SystemContext.getBeansWithAnnotation(Controller.class); // register all the controllers ...
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BeanContextcontext()Return the underlying BeanContext.static <T> TgetBean(Class<T> type)Return a single bean given the type.static <T> TgetBean(Class<T> type, String name)Return a single bean given the type and name.static <T> List<T>getBeans(Class<T> interfaceType)Return the list of beans that implement the interface.static <T> List<T>getBeansByPriority(Class<T> interfaceType)Return the list of beans that implement the interface ordering based on@Priority.static List<Object>getBeansWithAnnotation(Class<?> annotation)Return the list of beans that have an annotation.
-
-
-
Method Detail
-
context
public static BeanContext context()
Return the underlying BeanContext.
-
getBean
public static <T> T getBean(Class<T> type)
Return a single bean given the type.CoffeeMaker coffeeMaker = SystemContext.getBean(CoffeeMaker.class); coffeeMaker.brew();- Parameters:
type- an interface or bean type
-
getBean
public static <T> T getBean(Class<T> type, String name)
Return a single bean given the type and name.Heater heater = SystemContext.getBean(Heater.class, "electric"); heater.heat();- Parameters:
type- an interface or bean typename- the name qualifier of a specific bean
-
getBeansWithAnnotation
public static List<Object> getBeansWithAnnotation(Class<?> annotation)
Return the list of beans that have an annotation.// e.g. register all controllers with web a framework // .. where Controller is an annotation on the beans List<Object> controllers = SystemContext.getBeansWithAnnotation(Controller.class);- Parameters:
annotation- An annotation class.
-
getBeans
public static <T> List<T> getBeans(Class<T> interfaceType)
Return the list of beans that implement the interface.// e.g. register all web routes with web a framework List<WebRoute> routes = SystemContext.getBeans(WebRoute.class);- Parameters:
interfaceType- An interface class.
-
getBeansByPriority
public static <T> List<T> getBeansByPriority(Class<T> interfaceType)
Return the list of beans that implement the interface ordering based on@Priority.// e.g. register all web routes with web a framework List<WebRoute> routes = SystemContext.getBeansByPriority(WebRoute.class);- Parameters:
interfaceType- An interface class.
-
-