Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Standardize the ability to get references to objects when using CDI #44
Currently, if you look across the various specs, there's lots of ways to get object references. As far as I've seen, JAX-RS does it the best (definition wise) by specifying that classes annotated will be properly looked up via CDI. JSF has similarly followed suit and aligned their instance creation to CDI when within a bean archive. JMS has done an excellent job as well, with managing scopes of its managed objects.
However, we have specs like Servlet and WebSockets that don't define this behaviour. For instance, a SerlvetFilter should be a managed CDI object with an appropriate scope, and allow for proper injection, assuming it has an adequate scope and is found within a bean archive.
This type of requirement needs to come from the entire platform overall, in order to give developers a consistent programming model.
If you look, for example, JPA states the following:
In contrast, see the equivalent paragraph within the JAX-RS 2.0 spec
The JAX-RS version is simpler, however it more clearly (at least to me) explains how the JAX-RS implementation is meant to work with the CDI container. The JPA spec on the other hand makes this very confusing. It reads as though the JPA provider must still instantiate the the EntityListener, and somehow integrate with the CDI container to populate injection points within the EntityListener. The JPA spec could instead defer to the container, similar to what JAX-RS says about using CDI-style beans as EntityListeners.
If this were the case, then we could more generically say that across the board, if any spec wants to integrate with CDI then this is how it should be done.