HubSpot / dropwizard-guice

Adds support for Guice to Dropwizard
Apache License 2.0
266 stars 95 forks source link

Injecting Jersey request-scoped services for explicit bindings #87

Closed vvondra closed 6 years ago

vvondra commented 8 years ago

In the PR merging support for DW 1.0 I commented that injecting a Provider<SecurityContext> into our Guice bound services does not work anymore. https://github.com/HubSpot/dropwizard-guice/pull/86#discussion_r75580088

It's due to the baseInjector not having the JerseyGuiceModule installed. The child injectors used for AutoConfig, the one in getInjector and the one bridged to HK2 have it installed however.

The code in the PR is more of an example of the set up we had (in the tests). The little hack installing new JerseyGuiceModule(JerseyGuiceUtils.newServiceLocator()) into baseInjector however breaks two existing tests.

Do you see any solution how to be able to inject Providers for Jersey-backed services?

vvondra commented 7 years ago

@heldeen I've rewritten this PR a bit

See what I meant above in this comment https://github.com/HubSpot/dropwizard-guice/pull/87#r97233832

I am not able to explicitly bind anything which relies on Provider (or something else provided by the JerseyModule), since the initialization happens too early.

Now this PR adds a possibility to add Guice modules which are only added in the childInjector called in getInjector when all the necessary parts are ready.

Now it passes all the existing test cases in the project + my new one.

I've kept the addModule behaviour the same for backward compatibility.

vvondra commented 6 years ago

Not going anywhere I suppose, and definitely out of my scope now, let's cleanup.