Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

@Hk2Inject does not work on the constructors of Guice services #183

Closed
glassfishrobot opened this issue Oct 28, 2013 · 12 comments
Closed

@Hk2Inject does not work on the constructors of Guice services #183

glassfishrobot opened this issue Oct 28, 2013 · 12 comments
Assignees
Milestone

Comments

@glassfishrobot
Copy link
Contributor

The Guice bridge fails to inject the following code:

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

Guice understands @Inject, Injector but not UriInfo. The bridge never kicks in for UriInfo, so HK2 never gets asked to supply a value. Guice fails, saying that UriInfo is not bound to an implementation.

@HK2Inject is not applicable on class constructors so it can't be used. I'm not sure it would help even if we could annotate the constructor this way.

This is reproducible always.

Affected Versions

[2.2.0]

@glassfishrobot
Copy link
Contributor Author

Reported by cowwoc

@glassfishrobot
Copy link
Contributor Author

Issue-Links:
is related to
HK2-121
JERSEY-1950

@glassfishrobot
Copy link
Contributor Author

cowwoc said:
(This issue is related to #165)

@glassfishrobot
Copy link
Contributor Author

cowwoc said:
I filed a bug report with Guice: https://code.google.com/p/google-guice/issues/detail?id=778

I could really use a second set of eyes. Can you verify that the problem is really on their end?

@glassfishrobot
Copy link
Contributor Author

@jwells131313 said:
I will at least look to see if @HK2Inject can be used with constructors. As I remember Guice is kind of limited in this respect, but I'll look into it.

My assumption is that the class you are describing here (DepartmentsResource) is being created by Guice, but that UriInfo, since it comes from Jersey should be provided by HK2.

@glassfishrobot
Copy link
Contributor Author

@jwells131313 said:
Instead of doing constructor injection can you use a setter or field injection with UriInfo? Like:

@javax.inject.Inject
public DepartmentsResource(Injector injector)

{...}

@HK2Inject
public void setUriInfo(UriInfo uriInfo) {...}

?

At least then we can see if you can get UriInfo injected into your Guice service.

@glassfishrobot
Copy link
Contributor Author

cowwoc said:
Yes, that works. But I have a strong preference for constructor injection (which my entire codebase relies upon).

@glassfishrobot
Copy link
Contributor Author

@jwells131313 said:
Right, but I think Guice does not have the capability to allow others to help with their constructors (like HK2 does!). So I think you will need to get Guice to fix this or live with the restriction.

@glassfishrobot
Copy link
Contributor Author

cowwoc said:
I agree that Guice's extensibility leaves a lot to be desired but it shouldn't matter whether Guice is extensible or not. The only thing that should matter is what features Jersey depends on and whether Guice provides them. I believe Guice provides all the necessary features, so long as we add an abstraction layer between Jersey and the DI provider.

@glassfishrobot
Copy link
Contributor Author

@jwells131313 said:
I think that until https://code.google.com/p/google-guice/issues/detail?id=778 is fixed in Guice that we cannot help with the construction of Guice objects.

@glassfishrobot
Copy link
Contributor Author

This issue was imported from java.net JIRA HK2-139

@glassfishrobot
Copy link
Contributor Author

Closing this as this issue is migrated to eclipse-ee4j/glassfish-hk2#184

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

No branches or pull requests

2 participants