JSR-299 (CDI) introduces the concept of a resource (unfortunately named): http://docs.jboss.org/weld/reference/1.0.0/en-US/html/resources.html#d0e4373
You can imagine a resource in this nomenclature as a bridge between the Java EE 6 brand for dependency injection (@EJB, @Resource, @PersistenceContext, etc.) and the CDI injection brand.
The general point is that somewhere (and this will be the root of my question) you declare what the bridge class is: it contains fields annotated with both Java EE @EJB and comments @PersistenceContext or @Resource and with CDI @ Sets annotations. The net effect is that Java EE 6 introduces a persistence context, say where it invoked, and the CDI recognizes that it introduced the PersistenceContext as a source for future injections along the line (processed by @Inject).
My question is: what is community consensus - or is there one - on:
- what this class of bridge should be called
- where should this class of bridge exist
- Is it better to localize all these things in one class or to make several of them
...
Remaining on my devices, I thought about declaring one class with a name CDIResourcesand using it as One True Place to bind Java EE DI to CDI DI. Many examples do something similar, but I don’t understand if they are “fair” examples or is this a good way to do this.
Thank.
source
share