[cdi-dev] [JBoss JIRA] Commented: (CDI-14) Add instance() method to BeanManager
Fab Mars (JIRA)
jira-events at lists.jboss.org
Wed May 11 03:13:18 EDT 2011
[ https://issues.jboss.org/browse/CDI-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12601221#comment-12601221 ]
Fab Mars commented on CDI-14:
At first I roared on the fact a convenience method wasn't available. As everyone else, I wrote a utility class with the 3 lines needed (resolve/createCreationalContext/getReference). It was actually longer to understand the difference between these and InjectionTarget#produce() because the documentation chapter 16.4 was confusing me.
Then I realized you can almost always find a way to work properly, so getting bean refs by hand becomes very, very rare (eg: phaselisteners, components you really have to new() yourself).
What bothered me much more was the lifecycle of such beans. I aksed myself questions like: "If the bean instance was actually instantiated via getReference, will its lifecycle be still respected?"
Eventually, I thought the only thing needed would be extra documentation. I actually shared Mark's point sometimes.
Now I'd say it's useless to let every EE developper write the exact same 3 lines of code, so it's better to have a couple of convenience methods (Rick's proposal sounds neat)...BUT I already see deviant behaviors coming amongst the developpers, so I'd be extremely clear on the spec, in the javadoc and in the reference doc about what getting bean refs by hand implies.
> Add instance() method to BeanManager
> Key: CDI-14
> URL: https://issues.jboss.org/browse/CDI-14
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Resolution
> Affects Versions: 1.0
> Reporter: Pete Muir
> Fix For: 1.1 (Proposed)
> Currently obtaining a contextual reference is quite a complex operation, adding a method like:
> Instance<Object> instance();
> would make it much easier.
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the cdi-dev