Will (or should) CDI provide package qualifiers?

Studying Seam 3, I found that Seam Solder allows you to apply the @Named annotation to packages - in this case, all the beans in this package will be automatically named as if they were qualified by @Named themselves. I did not see too many advantages in do something like this (and you can tell me some situations when it might be useful!), but it made me think: it would not be wise for the CDI (or Seam Solder) to allow arbitrary qualifiers that will apply to packages too while maintaining the same semantics of this @Named qualifier? Is this possible functionality in future versions of the CDI specification? Is there any reason not to allow this?

+4
source share
1 answer

I have not seen too many advantages in doing something like this (and you can tell me some situations where this can be useful!)

@Named (as you probably know) makes an accessible bean accessible from JSF pages. Applied at the package level, it will simply assign an EL name to all beans in this package. Although I agree with you that this is certainly not a killer function, I can imagine that quite often everything that is required in a particular package should be available through EL. Of course, another question, if you annotate all the beans individually, would not be better in terms of readability.

would it be wise for the CDI (or Seam Solder) to allow arbitrarily qualifiers that would apply to packages, while maintaining the same semantics of this @Named classifier?

@SomeQualifier would apply the same qualifier to all beans in the package. Contrary to @Named , I can hardly imagine that this makes sense - looking back at a couple of CDI projects over the past year, I think I never had a package where all the beans in it required the same qualifier. Some sense makes sense if you remember that qualifiers are designed to decouple components ... (Let's say you have an interface with three implementations - almost certainly they will belong to different packages or even jars)

+1
source

All Articles