[cdi-dev] [JBoss JIRA] (CDI-170) Either ditch or fix @New
Mark Struberg (Commented) (JIRA)
jira-events at lists.jboss.org
Wed Oct 26 09:23:45 EDT 2011
[ https://issues.jboss.org/browse/CDI-170?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12637578#comment-12637578 ]
Mark Struberg commented on CDI-170:
Sorry Jozef, I think I created this issues after a chat with Stu and Pete on IRC. Thus I might probably have left out parts of the argumentation chain.
1st (what might've be missing): @New has almost no benefit over @Dependent when your MyBean is in a BDA (jar with META-INF/beans.xml) The only benefit is when MyBean has already a different Scope than @Dependent - but there are easy workarounds which don't need @New even for that case.
This was also in long terms discussed by the EG in 2008. See also the later added restriction that (3.12):
> is enabled, in the sense of Section 5.1.2, “Enabled and disabled beans”,
> if and only if some other enabled bean has an injection point with the
> qualifier @New(X.class) where X is the bean class.
@New has the benefit that you can create 'managed' contextual instances with injection applied even if MyBean is *NOT* in a BDA (jar with META-INF/beans.xml). But in this case MyBean will most likely DON'T have an @Inject annotated constructor (thus a default ct must exist) and also no @SomeInterceptor annotation. Also since it's not part of any BDA the ProcessAnnotatedType will _not_ be fired for this class -> no 'dynamic' interceptor can be applied via Extensions. Which means MyClass will also don't have any interceptors...
So my arguing is split in 2 phases:
a.) @New makes no sense for BDAs (see above)
b.) @New makes no sense for non-BDAs (see above)
-> @New makes no sense at all ;)
> 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