[cdi-dev] [JBoss JIRA] (CDI-653) Introduce BeanManager#getInstances() to ease instance resolution in custom SPI

Antoine Sabot-Durand (JIRA) issues at jboss.org
Tue Nov 29 11:41:09 EST 2016


     [ https://issues.jboss.org/browse/CDI-653?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Antoine Sabot-Durand updated CDI-653:
-------------------------------------
    Fix Version/s: 2.0 .Final
                       (was: 2.1 (Discussion))


> Introduce BeanManager#getInstances() to ease instance resolution in custom SPI
> ------------------------------------------------------------------------------
>
>                 Key: CDI-653
>                 URL: https://issues.jboss.org/browse/CDI-653
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>            Reporter: Antoine Sabot-Durand
>             Fix For: 2.0 .Final
>
>
> Right now if you need a bean instance in one of your extension or custom SPI (i.e. instance of Bean A is needed to create Bean B) you have to write something like
> {code:java}
> Set<Bean<?>> beanSet = beanManager.getBeans(MyClass.class);
> Bean<?> bean = beanManager.resolve(beanSet);
> MyClass instance = (MyClass) beanManager.getReference(bean, MyClass.class, beanManager.createCreationalContext(bean));
> {code}
> While it can be useful to get thru all this step of type safe resolution, a typical use case is: I need this contextual instance (or these contextual instances) to do conditional action according to its state.
> So providing a Bean Manager method returning an {{Instance<Object>}} could be a short cut that could help a lot of advanced developers:
> {code:java}
> beanManager.getInstances().select(MyClass.class).get();
> {code}



--
This message was sent by Atlassian JIRA
(v7.2.3#72005)


More information about the cdi-dev mailing list