-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Javadoc for @Named is misleading to users of CDI #33
Comments
These I don't yet see an inconsistency between JSR-330
I believe that CDI is using As I see it, we need to careful using the term "bean name" (as opposed to "qualifier"). As I see it, "bean name" really can be different to a "qualifier" and used very differently by various DI implementations. Perhaps you can explain where you see the inconsistency? Is this something specific with use with JSF or something else?
That does not sound very acceptable from a JSR-330 perspective. CDI might not recommend use of The example in the Javadoc exactly matches the expected use for JSR-330 and there are a number of very popular DI libraries that indeed comply to the JSR-330 used of As I see it, there is now a really large amount of application code out there which is using |
My personal opinion is that CDI pretty much screwed up @rbygrave It's a little complicated. In CDI, an injection point I believe CDI should have used a new qualifier called |
While I agree with this, that doesn't help us solve the issue CDI has. |
For myself, I don't mind a note for CDI being added. I'd be reasonably confident that could be done in such a way that does not confuse JSR-330 users. [Removing the example from the Javadoc imo is not a viable option] I have a silly question: In CDI, if we have:
... and CDI transparently adds a
What is the purpose / expected use case for this? How is the combination of That is, why does CDI just NOT automatically add the Said differently, given the CDI docs recommending to not use Edit: Agh, note I'm also @rbygrave - apologies if that is confusing. |
Historical reasons and decisions I suppose. I wasn't there when this was done so take it with a pinch of salt but my guess is it was probably a perceived way of making it easier to inject those beans.
Adding the exception to the CDI spec could have been (again, just a speculation) a way to allow users to have a simple bean declaration that: Then again, according to my googling, the same or very similar text existed even in CDI 1.0 so it's really just guesswork :)
Note that CDI suggests that
What kind of fix do you have in mind? |
Not a silly question -- I explained it too briefly to be understandable. That's not what is happening. What's happening is the following. If I declare @Dependent // scope annotation, not using `@Singleton` for idiosyncratic reasons
public class MyBean1 {
} CDI automatically adds the Now, if I declare @Dependent
@MyQualifier
public class MyBean2 {
} CDI does not add Nothing terribly surprising here. There might be legitimate questions as to what is the purpose of the Now, if I declare @Dependent
@Named("myBean3")
public class MyBean3 {
} CDI does add Now, there are 2 important things:
With that said, it should be clear that:
The 3rd point is how I'm not exactly sure we can explain this succinctly in the
But that isn't terribly helpful 🤷 |
Is your feature request related to a problem? Please describe.
The CDI specification recommends that
@Named
is not used as a qualifier at injection points. However, the Javadoc for@Named
merely says that it's a string based qualifier and gives an example of it's use in this context.CDI uses
@Named
to assign a bean name for lookup from technologies like JSF. Bean names mostly have to be unique among the application.Describe the solution you'd like
Can we add a note to the
@Named
annotation indicating that CDI recommends against its use as a qualifier for injection points?Describe alternatives you've considered
We could just remove the example showing
@Named
used in the way that CDI recommends against.We could do nothing and acknowledge that the choice to have shared injection annotations means that the Javadoc can't be as helpful to users as we'd like.
Additional context
I realise that there are other consumers of
@Named
other than CDI (I'm aware of Spring and Guice). Any guidance for use in CDI would have to be written in a way that doesn't mislead users of these technologies.The text was updated successfully, but these errors were encountered: