开发者

Would (or should) CDI provide package qualifiers?

Studying Seam 3, I discovered that Seam Solder allows the @Named annotation to be applied to packages - in that case, all开发者_C百科 beans in this package will be automatically named, as if they were qualified with @Named themselves. I didn't see too much advantages on doing something like this (and you can point me some situations where it can be useful!) but it made me wonder: wouldn't it be reasonable to CDI (or Seam Solder) to allow arbitrary qualifiers to be applied to packages as well, maintaining the same semantics of this @Named qualifier? Is it a possible functionality in future versions of the CDI specification? Is there a reason for not allowing it?


I didn't see too much advantages on doing something like this (and you can point me some situations where it can be useful!)

@Named (as you certainly know) makes a managed bean accessible from within JSF pages. Applied on package level it will simply assign an EL name to all beans in that package. While I agree with you that this is certainly not a killer feature, I can imagine that quite often everything within a certain package needs to be accessed via EL. Of course it's another question if annotating all beans individually wouldn't be better in terms of readability.

wouldn't it be reasonable to CDI (or Seam Solder) to allow arbitrary qualifiers to be applied to packages as well, maintaining the same semantics of this @Named qualifier?

@SomeQualifier would apply the same qualifier to all beans in the package. Contrary to @Named I can hardly imagine that this would make much sense - looking back on a couple of CDI projects in the last year, I think I never had a package where all beans in it required the same qualifier. Kind of makes extra sense if you remember that qualifiers are meant for loose coupling of components... (Say you have an interface with three implementations - almost certainly those would belong into different packages or even jars)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜