[ACCEPTED]-Guice: Avoid lazy injection-guice
Accepted answer
Yes, bind it using .asEagerSingleton()
:
bind(Service.class).to(ServiceImpl.class).asEagerSingleton();
Note that according 4 to that link, Guice
will eagerly create all Singleton
s 3 if being run in the PRODUCTION
stage (it lazily creates 2 them in the DEVELOPMENT
stage for faster test deployment). You 1 can specify the Stage
when creating the Injector
:
Injector injector = Guice.createInjector(Stage.PRODUCTION, new MyModule());
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.