Closed mrserverless closed 6 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?
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
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:
Managed
Provider
for all run-phase dependencies such asEnvironment
andConfiguration
startup()
callProvider.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.