users@hk2.java.net

Re: _at_Inject specific instance

From: Trenton D. Adams <trenton.d.adams_at_gmail.com>
Date: Wed, 20 Apr 2016 16:55:35 -0600

I get it now, there is no way of doing this. It's called Context and
Dependency Injection for a reason, because the framework using CDI should
have the context of each object instance, in which case it will know how to
provide injections from a factory, based on the context.

@Context HttpServletRequest request in the case of JAX-RS simply means
inject the current servlet request, the framework knows the context, so
it's able to do that.

Am I on the right track here?

On Tue, Apr 19, 2016 at 7:12 PM, Trenton D. Adams <trenton.d.adams_at_gmail.com
> wrote:

> So I've created some basic HK2 services and what not, and HK2 is able to
> create instances for me. What I don't see any of the docs mentioning is
> how to get a specific instance of a Class injected into another class.
>
> When I specify...
> @Inject private SpecialClassInterface specialClass;
> SpecialClass gets injected as a new empty instance. But what I want is it
> to be injected with the instance I wanted it injected with. I don't see
> any docs on that.
>
> I'm guessing it might be a more fundamental lack of understanding of HK2
> as a whole, but I don't know where to start. I've read quite a bit of
> docs, and nothing mentions this.
>