HK2 needs to be able to delegate injection to CDI provider. Generic support is preferrable, but GlassFish specific support would be good enough.
The typical use case for CDI / JAX-RS (Jersey) integration is a CDI bean (whose life-cycle is managed by CDI container) but is at the same time a JAX-RS resource that needs Jersey to satisfy the JAX-RS specific injection points. E.g.:
In the example above the FooResource needs to be managed by a CDI container and when Jersey tries to retrieve an instance of it via HK2 (e.g. via ServiceLocator.getService(FooResource.class)), the HK2 needs to recognize the bean is managed by an external container (CDI) and needs to retrieve it from that container.
Also, the HK2 needs to be able to register an CDI extension bean in the CDI container that will be able to resolve custom (in our case JAX-RS) injection points that were added to the HK2 ServiceLocator by Jersey.
In summary, the process of retrieval of an externally managed (CDI) component by Jersey via HK2 should look like:
- Jersey asks HK2 for a component instance
- HK2 does not have a descriptor so it consults the external provider(s) (in our case CDI) to provide the component instance
- External provider creates and injects the instance
- During that phase external provider consults HK2 integration layer (in our case a CDI extension) to resolve the unsatisfied (JAX-RS/Jersey specific) injection points
- External provider returns the component to HK2
- HK2 passes the component to Jersey
Note that the above could be converted into a generic HK2 external component provider API that is not necessarily CDI specific, but could be reused to integrate other injection providers too (Spring, Guice, ...). Obviously I do not insist on this particular solution. The important part is the use case demonstrating the problem that we need to solve.