GithubHelp home page GithubHelp logo

Comments (8)

eliast avatar eliast commented on August 24, 2024

Agreed. Why don't you give it a try and report back? Funny enough, I'm moving to Governator and everything is working really well. Finally in Stage.PRODUCTION! but don't have the issue you describe. FYI, I usually add an expensive initialization as part of my healthcheck because I like to warm up the JVM before adding it to my load balancers.

from dropwizard-guice.

jhaber avatar jhaber commented on August 24, 2024

So you want it to be an eager singleton that has access to Environment/Configuration? As @chbatey noted on #19 this can be achieved by moving injector creation to the run method, but at the expense of not being able to autoconfig bundles which some users might rely on.

One possible workaround is to make the singleton lazy and have a managed that initializes it inside the start method (or a healthcheck as @eliast suggested), so you effectively get an eager singleton

from dropwizard-guice.

flavor8 avatar flavor8 commented on August 24, 2024

I'm trying the lazy healthcheck approach. Your updated documentation for #41 helps; it didn't occur to me that it's safe to hold a reference to the GuiceBundle in the application class to make it visible to the run method (I was experimenting with the container, which the environment can return).

Nevertheless there seems to be a square peg and round hole here; is there any way to smooth the edges?

Could you also provide a documentation example for chbatey's approach? (It sounds like he made a pull request, which may be worth looking at.) Specifically, how do you register the bundle given that you don't have a handle on bootstrap in the run method?

Thanks

from dropwizard-guice.

eliast avatar eliast commented on August 24, 2024

Agreed on the square peg. But there are all kinds of gotchas and nobody has submitted a PR request that actually solves it yet. ;-) Basically, if we want to support bundle injection then we have to create the injector in initialize, else we could initialize the injector during the run phase and everything would be good.

If we keep it this way, we can do everything, we just need to know the exact steps to follow. Not very ideal but works.

from dropwizard-guice.

flavor8 avatar flavor8 commented on August 24, 2024

I got this working using autoconfig + healthchecks.

Theoretically, what would dropwizard need to support to make this more seamless? I.e. what might a possible pull request for dropwizard 0.8 contain that would allow first class guice support?

from dropwizard-guice.

mrserverless avatar mrserverless commented on August 24, 2024

@flavor8 dropwizard uses Jersey which has HK2 built in as injector. Therefore by default, Guice will be an add-on instead of being first class. I'm experimenting with the HK2 Guice Bridge at the moment to see if Guice can work with dropwizard 0.8

from dropwizard-guice.

htamas avatar htamas commented on August 24, 2024

Any update on this issue?

from dropwizard-guice.

jhaber avatar jhaber commented on August 24, 2024

Since this issue 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

from dropwizard-guice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.