From Marek ...
In Jersey 1.x, we have first consulted the external providers and only then fell back to the default Jersey injection.
Additionally, there are several types of injection providers recognized by original Jersey 1.x code:
- providers that instantiate and inject the component, but JAX-RS/Jersey injection is then performed by Jersey runtime as well as component lifecycle is managed by Jersey
- providers that instantiate, inject and manage the injected component lifecycle, but JAX-RS/Jersey injection is then performed by Jersey runtime
- providers that instantiate, inject and manage the injected component lifecycle, including JAX-RS & Jersey injection
FWIW, I have also found a provider type that lets jersey instantiate, inject and manage the component and only wraps the component into a proxy, but I failed to find an external use case for this type of provider.
...it makes sense to distinguish between "eager" and "fallback" providers. Also, HK2 needs some strategy for instantiation of injected components. Sometimes the component should be provided by the external provider rather than instantiated directly, e.g. JAX-RS resources implemented as CDI managed beans or EJBs.
Today, Jersey 2.x would typically do this to get a JAX-RS resource class instance:
SomeResource resource = injector.inject(SomeResource.class);
The above assumes that HK2 is able to decide who is responsible for creating/providing the instance, injecting it (fully or partially) and managing the instance lifecycle.