[cdi-dev] [JBoss JIRA] (CDI-170) Either ditch or fix @New

Mike Brock (JIRA) jira-events at lists.jboss.org
Wed Aug 15 16:09:14 EDT 2012


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

Mike Brock edited comment on CDI-170 at 8/15/12 4:07 PM:
---------------------------------------------------------

The elimination of {{@New}} is actually quite high on my list of CDI features I'd eliminate if I had a magic wand. It's not as high as my desire to remove narrower-scope injection. But it's pretty high.

To me, {{@New}} is something you'd basically never use in a new system built on CDI. At least, I'd never use it. I'd jump through hoops not to. But you _may_ find it necessary to use in a system you are maintaining, when you're stuck with a bad design decision made by someone else that you simply can't change. It stretches the limits of my imagination to come up with a scenario where this may be, but I'll just assume it does.

CDI is a declarative programming model. And I think a desirable characteristic of any declarative programming model, is that the meaning of declarative constructs be as plain and straight forward is as reasonably possible. 

I believe {{@New}} directly undermines this goal. It creates an information asymmetry between what a bean declares its scope to be, and what the scope may actually be at the injection site. To me, this is a particularly offensive characteristic. But I'm not count on winning anyone over on my desire to nix/deprecate {{@New}}. I merely wanted to voice my opinion on the matter. There are, in fact, other hills I'd feel more morally righteous about dying on than this one.

P.S. I implemented this in Errai CDI with great hemming and hawing, pain shooting up my spine, with tears of blood flowing down my cheeks.
                
      was (Author: cbrock):
    The elimination of {{@New}} is actually quite high on my list of CDI features I'd eliminate if I had a magic wand. It's not as high as my desire to remove narrower-scope injection. But it's pretty high.

To me, {{@New}} is something you'd basically never use in a new system built on CDI. At least, I'd never use it. I'd jump through hoops not to. But you _may_ find it necessary to use in a system you are maintaining, when you're stuck with a bad design decision made by someone else that you simply can't change. It stretches the limits of my imagination to come up with a scenario where this may be, but I'll just assume it does.

CDI is a declarative programming model. And I think a desirable characteristic of any declarative programming model, is that the meaning of declarative constructs be as plain and straight forward is as reasonably possible. 

I believe {{@New}} directly undermines this goal. It creates an information asymmetry between what a bean declares its scope to be, and what the scope may actually be at the injection site. To me, this is a particularly offensive characteristic. But I'm not count on winning anyone over on my desire to nix/deprecate {{@New}}. I merely wanted to voice my opinion on the matter. There are, in fact, other hills I'd feel more morally righteous about dying on than this one.
                  
> Either ditch or fix @New
> ------------------------
>
>                 Key: CDI-170
>                 URL: https://issues.jboss.org/browse/CDI-170
>             Project: CDI Specification Issues
>          Issue Type: Bug
>          Components: Concepts, Contexts
>    Affects Versions: 1.0
>            Reporter: Mark Struberg
>             Fix For: 1.1 (Proposed)
>
>
> The specification of @New is currently not really usable. It is really only for creating injected but unmanaged and unintercepted instances of a class. But this usecase is weird and imo just not needed. If the class under construction is an 'old' Pojo (without @Inject, etc) then it doesn't need to get managed. And it also doesn't provide any benefit over just using new Pojo();
> Also you cannot @New classes which don't have a default ct.
> I just found no sane scenario where we cannot use a producer method instead.
> Can we simply deprecate @New?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the cdi-dev mailing list