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

Allow overriding of Scope at Injection Point

    Details

    • Type: Feature Request
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Rejected
    • Affects Version/s: 2.0 .Final
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      Allow overriding scopes at injection point.

      @SessionScope
      public class FeatureState {...}
      
      public class Bean B {
        @Inject
        @ConversationScoped //Overriding original scope
        public BeanA beanA;
        ...
      }
      

      Sample use-case for for a feature flag:

      @Alternative
      public class FeatureStateProducer {
      
        @Inject
        @SessionScoped
        private FeatureState devState;
      
        @Inject
        @ConversationScoped
        private FeatureState viewState;
      
        @Inject
        private JNDIProvider jndiProvider;
      
        private boolean viewOnly = true;
      
        @PostConstruct
        public void postConstruct() {
          this.viewMode = ...; //read config.
        }
      
        @Produces
        public FeatureState produce() {
          return viewOnly ? viewState : devState;
        }
      
      }
      

      Currently this can be solved by overriding scope with @Qualifiers:

      @ViewMode
      @ConversationScoped
      public class ViewFeatureState extends FeatureState {...}
      
      @DevMode
      @SessionScoped
      public class DevFeatureState extends FeatureState {...}
      

      Risks:

      • developers might start to define the scopes at IP and on bean (hard to maintain).
      • confusing when debugging, annotation on bean, e.g. @ApplicationScoped yet behaving differently.
      • etc...

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                sknitelius Stephan Knitelius
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: