Dnia 20 lutego 2013 14:54 Marek Potociar <marek.potociar_at_oracle.com> napisaĆ(a):
>
> On Feb 19, 2013, at 6:38 PM, marianl <marianl_at_o2.pl> wrote:
>
> > Hello,
> >
> > I have DI container and I'd like to expose its singletons for Jersey.
> > I've seen that there are AbstractBuilder and Injections which might help with that.
> >
> > Getting instances from picocontainer and binding them inside AbstractBuilder#configure method works, but I don't want to do eager binding. I'd like to create instances later, when they are needed.
> >
> > How can I achieve that?
>
> Use HK2 org.glassfish.hk2.api.Factory concept. That's essentially a "source" Provider as it is known in JSR 330 (Java DI).
>
> And then in your Binder implementation you would use:
>
> bindFactory(MyFactory.class).to(ContractA.class)...
>
> ...or similar construct.
>
> HTH,
> Marek
Thanks for reply. My team mate implemented it on proxy before I had chance to try suggested approach. At the end of the day, it works just fine.
Kind regards,
Marek Lewandowski
> >
> > Issues I've encountered:
> > I don't how can I use class bindings because when I tried that then HK2 says it cannot resolve dependencies. Is there some contract I need to implement to get a chance of providing concrete instance of desired type?
> > I don't know if I'm missing something or there is other way to do it.
> >
> > Possible solution:
> > Bind java.lang.reflect.Proxy which will do lazy resolution.
> >
> > Kind regards,
> > Marek
>
>