Uploaded image for project: 'CDI Specification Issues'
  1. CDI Specification Issues
  2. CDI-653

Introduce BeanManager#getInstances() to ease instance resolution in custom SPI

    XMLWordPrintable

Details

    • Feature Request
    • Resolution: Done
    • Major
    • 2.0 .Final
    • None
    • None
    • None

    Description

      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

      Set<Bean<?>> beanSet = beanManager.getBeans(MyClass.class);
      Bean<?> bean = beanManager.resolve(beanSet);
      MyClass instance = (MyClass) beanManager.getReference(bean, MyClass.class, beanManager.createCreationalContext(bean));
      

      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:

      beanManager.getInstances().select(MyClass.class).get();
      

      Attachments

        Activity

          People

            asabotdu@redhat.com Antoine Sabot-Durand (Inactive)
            asabotdu@redhat.com Antoine Sabot-Durand (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: