I'm using dw Manged object to start db services and synchronize schema. It's the default dw point for lifecycle-related staff. Also, I wrote https://github.com/xvik/dropwizard-guicey which registers managed objects for me, so I'm always on "guice side" (no direct injector usage required for manual integration)
четверг, 17 сентября 2015 г., 4:12:00 UTC+6 пользователь scl написал: > > Guice is a dependency injection framework. Its nothing more. > > The scenario 1 can be summarized as: > "Run some code once at application startup." > Then do it. Run the code at application startup. Don't try to make Guice > run the code for you. > i.e. in the dropwizard application class there is a method initialize(). > > For your scenario 2 you want some timer task. > You won't find this in Guice. But there are extensions which provide such > functionality. > One would be: http://onami.apache.org/scheduler/ > There are more out there. Pick the one that suits your needs best. > > > > > On 09/16/2015 04:20 PM, [email protected] <javascript:> wrote: > > Hi, > > I am currently working with guice and dropwizard. I am NOT using the > dropwizard-guice dependency since this is somewhat broken with the latest > dropwizard version. Fortunatelly I found a nice tutorial explaining how to > get this set up so I can use guice. I however have a few issues now, where > coming from spring, I am struggling to find the alternative/best practise > for it. > > Scenario 1: > I have a bean that simply checks at startup that the schema of my database > is present. I solved this by doing: > > @Provides @Singleton public bla() { > // object > // init > } > > The issue is, that I now have to run guice in production. I am feeling > that I am abusing the eager singleton creation in production and not doing > the right thing here. > How do I create standalone beans that get created and do some work. In > spring I would create this and then call an init method on it. In guice I > am not sure how to solve this. > > > Scenario 2: > Timer Tasks that are scheduled or simply threads. E.g. a Monitoring thread > that gets metric in and pokes them to a reporting server once a minute. I > have the same issue here, > i can create the bean, but I can't call run on it. Also, if I am not in > production, since the bean itself is not used anywhere, it won't get > created and won't do any work. > > It'd be great if someone could give me some pointer for this :) > > Thanks, > > Artur > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] <javascript:>. > To post to this group, send email to [email protected] > <javascript:>. > Visit this group at http://groups.google.com/group/google-guice. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-guice/2cf2b64e-38fb-416d-a1ff-dd56618b9b99%40googlegroups.com > > <https://groups.google.com/d/msgid/google-guice/2cf2b64e-38fb-416d-a1ff-dd56618b9b99%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > > > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-guice. To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/1fd13f21-5a02-4eca-ad34-0a38297ac319%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
