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

cdi instance injection ordering



    • Feature Request
    • Resolution: Obsolete
    • Optional
    • 2.1 (Discussion)
    • None
    • Beans
    • None


      We should allow ordering of bean instance injection using the Instance<MyBeanInterface> when an instance injection is used.

      Use case:

      Developer always define a kind of chain of processor beans, which may need to run in specific order.

      Current scenario:

      Using the Instance injection mechanism, a developer can inject multiple beans implementing the same interface and iterate of them. In order to ensure ordering, the developer could do one of the following:


      private Iterable<MyBeanInterface> myBeans;
      void injectBeans(@Any Instance<MyBeanInterface> myBeans) {
        //the create order does some kind of ordering on the beans.
         this.myBeans = createOrder(myBeans);

      This second option may be expensive if we have to order the beans everytime we execute the logic, and if this bean is applicationscoped, it wont make sense to do the ordering in the method call.

      private Instance<MyBeanInterface> myBeans;
      public void doSomething() {
        Iterable<MyBeanInterface> orderedbeans = createOrder(myBeans.select(someQualifier));

      Our Proposal

      We already have javax.annotation.Priority or any cdi specific annotation which we can add to MyBeanInterfaceImpl so that on injection of an Instance<MyBeanInterface>, all possible injection values are sorted based on the Priority.value() and if no annotation is defined, defaults to Priority.value = Integer.MAX_VALUE

      public interface MyBeanInterface {}
      public class MyFirstBean implements MyBeanInterface{
      public class MySecondBean implements MyBeanInterface{
      public class MyBeanProcessor {
        //We expect that this injected instances shall be in order based on the @Priority annotation
        private Instance<MyBeanInterface> myBeans;




            Unassigned Unassigned
            marembo2008 Ochieng Marembo (Inactive)
            2 Vote for this issue
            7 Start watching this issue