Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFE: Ability to delegate injection for unknown types #778

Open
gissuebot opened this issue Jul 7, 2014 · 8 comments
Open

RFE: Ability to delegate injection for unknown types #778

gissuebot opened this issue Jul 7, 2014 · 8 comments
Labels

Comments

@gissuebot
Copy link

From cowwoc@bbs.darktech.org on October 28, 2013 06:11:49

Use-case: Jersey 2.0 depends on HK2 (an implementation of JSR330). In order to integrate Guice into Jersey 2.0 I am building a Guice-HK2 bridge whereby HK2 delegate to Guice for unknown types and Guice delegates to HK2 for unknown types (with a mechanism to prevent endless loops).

HK2 already has a mechanism to defer injection to Guice, but Guice does not provide a mechanism to defer injection to HK2. I tried using TypeListener and asking for help on the mailing list but there doesn't seem to be a way to implement this as of Guice 3.0.

When trying to inject the following:

@javax.inject.Inject
public DepartmentsResource(com.google.inject.Injector injector, javax.ws.rs.core.UriInfo uriInfo)

Guice understands @Inject, Injector but not UriInfo. It never invokes the TypeListener for DepartmentsResource or UriInfo, so I don't have the chance to register a MembersInjector to delegate injection to HK2.

Original issue: http://code.google.com/p/google-guice/issues/detail?id=778

@gissuebot
Copy link
Author

From mcculls on October 28, 2013 04:11:52

FWIW this is my old BindingFactory patch from issue 49 - it still needs updating to apply cleanly against master, but may be useful as a starting point for discussion.

Attachment: gist
   BindingFactory.txt

@gissuebot
Copy link
Author

From sberlin on October 28, 2013 08:25:46

How is this different than issue 49 ?

@gissuebot
Copy link
Author

From cowwoc@bbs.darktech.org on October 28, 2013 08:37:34

Not sure, though maybe the use-case is different. Issue 49 was a bit vague to begin with. I have provided a concrete use-case, with strong demand [1], with no known workaround.

[1] See the number of votes on https://java.net/jira/browse/JERSEY-1950 (this is a large number by Jersey standards).

@gissuebot
Copy link
Author

From cowwoc@bbs.darktech.org on October 28, 2013 12:38:12

Another approach (which doesn't seem to be covered by issue 49 ) is to extend TypeListener to cover constructor injection. If TypeListener were fired for DepartmentsResource I could register the equivalent of MemberInjector for the constructor parameters.

@gissuebot
Copy link
Author

From cowwoc@bbs.darktech.org on October 31, 2013 14:34:52

Sam,

Who do we need to bring on board to move this issue forward?

@gissuebot
Copy link
Author

From sberlin on October 31, 2013 16:01:43

I'm not sure.  Is there a reason that Stuart's suggested flow (use a module that takes other modules and uses the SPI to scan them & write binding statements for the remaining injection points) won't work for you?

Guice very strongly leans against allowing this kind of autobinding.

@gissuebot
Copy link
Author

From cowwoc@bbs.darktech.org on October 31, 2013 17:21:20

I guess I didn't fully understand what he meant. Did he mean I should inject a Guice Module that takes HK2 DynamicConfiguration as input and convert DynamicConfiguration bindings into Module bindings?

Guice seems to be geared towards binding a configuration at init time, whereas HK2 allows bindings to change at runtime. (John Wells, please correct me if I'm wrong.)

It's not clear to me how I'd add/remove/modify bindings at runtime with Guice, even if I could register an event listener for HK2's DynamicConfiguration.

Injector.createChildInjector() allows me to add new bindings at runtime, but it's not clear how to change/remove them at a later time.

I've asked John to provide us with some background information about HK2 because I'm not very familiar with how it work.

@gissuebot
Copy link
Author

From jwells131313 on December 03, 2013 11:59:19

HK2 does indeed allow for dynamic additions and removals of underlying
descriptors at any time (given the proper permissions).  This ends up being
useful in dynamic systems such as OSGi systems or really any module system
(jigsaw etc).  I guess more specific questions would get more specific
answers lol.  More information can be found here of course: https://hk2.java.net/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant