
上QQ阅读APP看书,第一时间看更新
CDI
This is an abstract class that uses Java Service Loader to retrieve a concrete CDI class from the implementation:
CDI<Object> cdi = CDI.current();
CDI gives faster access to the BeanManager with the CDI.getBeanManager() method, but more interestingly, a simple way to request a contextual instance is provided without using the impactful code through the BeanManager.
Because CDI extends Instance<Object>, the contextual instance resolution is naturally provided through a programmatic lookup.
To make it simple, the access to CDI in our non CDI code, the specifications provide an alternative to the injection. Here you can see the injection of a bean:
@Inject @Any Instance<Object> cdi;
The same thing can be done through the CDI class as:
CDI<Object> cdi = CDI.current();
MyService service = cdi.select(MyService.class).get();