[ACCEPTED]-Guice: Avoid lazy injection-guice

Accepted answer
Score: 25

Yes, bind it using .asEagerSingleton():

bind(Service.class).to(ServiceImpl.class).asEagerSingleton(); 

Note that according 4 to that link, Guice will eagerly create all Singletons 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());

More Related questions