[cdi-dev] [JBoss JIRA] (CDI-628) Allow overriding of Scope at Injection Point

Stephan Knitelius (JIRA) issues at jboss.org
Thu Sep 8 06:38:00 EDT 2016


    [ https://issues.jboss.org/browse/CDI-628?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13290424#comment-13290424 ] 

Stephan Knitelius edited comment on CDI-628 at 9/8/16 6:37 AM:
---------------------------------------------------------------

[~meetoblivion] thanks for pointing that out. 

I guess this can be rejected/closed. Hardly any benefit and a lot of very good points against it.


was (Author: sknitelius):
[~meetoblivion] thanks for pointing that out, pretty sure we have come to the conclusion that this is a bad idea :)

> Allow overriding of Scope at Injection Point
> --------------------------------------------
>
>                 Key: CDI-628
>                 URL: https://issues.jboss.org/browse/CDI-628
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>    Affects Versions: 2.0 (proposed)
>            Reporter: Stephan Knitelius
>            Priority: Minor
>
> Allow overriding scopes at injection point.
> {code}
> @SessionScope
> public class FeatureState {...}
> public class Bean B {
>   @Inject
>   @ConversationScoped //Overriding original scope
>   public BeanA beanA;
>   ...
> }
> {code}
> Sample use-case for for a feature flag:
> {code}
> @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;
>   }
> }
> {code}
> Currently this can be solved by overriding scope with @Qualifiers:
> {code}
> @ViewMode
> @ConversationScoped
> public class ViewFeatureState extends FeatureState {...}
> @DevMode
> @SessionScoped
> public class DevFeatureState extends FeatureState {...}
> {code}
> 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... 



--
This message was sent by Atlassian JIRA
(v6.4.11#64026)


More information about the cdi-dev mailing list