Skip to content

Enable EagerSingletons using Managed and Guice Provider#70

Closed
mrserverless wants to merge 1 commit into
HubSpot:masterfrom
mrserverless:eagersingleton
Closed

Enable EagerSingletons using Managed and Guice Provider#70
mrserverless wants to merge 1 commit into
HubSpot:masterfrom
mrserverless:eagersingleton

Conversation

@mrserverless
Copy link
Copy Markdown
Contributor

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
Copy link
Copy Markdown

@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
Copy link
Copy Markdown
Member

jhaber commented Aug 21, 2018

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

@jhaber jhaber closed this Aug 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants