HubSpot / dropwizard-guice

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

Enable EagerSingletons using Managed and Guice Provider #70

Closed mrserverless closed 6 years ago

mrserverless commented 9 years ago

I've added a test to demonstrate a potentially more elegant solution to the eager singleton issue, highlighted in #40, #31 and #19.

The steps are:

  1. Implement Managed
  2. Inject in Provider for all run-phase dependencies such as Environment and Configuration
  3. Inside startup() call Provider.get()

This approach will avoid the initial performance hit cause by @LazySingleton. Since all lazy loading is done during run-phase, not at the first request. Compared to double injection (#46) I think this has less impact on existing design and uses what's already available.

ESPNMichaelKidd commented 9 years ago

@yunspace I'm following the basic concept behind using managed here, but I'm having a hard time wrapping my head around how I would leverage this to to provide an environment to a method in my Module class. For example, using the environment to provide a jersey client. Is this possibly using your managed approach?

jhaber commented 6 years ago

Sorry for the lengthy delay. Since this PR was opened we have introduced dropwizard-guicier which creates the Guice injector during the run phase which solves the problems with eager singletons: https://github.com/HubSpot/dropwizard-guicier