Eager singletons

Guice provides special syntax for making an object that has the singleton scope, and is initialized to eager mode rather than lazy mode. Following is the syntax:

bind(NotificationService.class).to(SMSService.class).asEagerSingleton();

Eager singletons uncover initialization issues sooner, and guarantee end users get a reliable, smart encounter. Lazy singletons empower a quicker edit-compile-run development cycle. We can utilize the stage enum to indicate which procedure ought to be utilized.

The following table defines stage-wise use of syntax of the singleton and supported object initialize mode:

Syntax PRODUCTION DEVELOPMENT
@Singleton eager* lazy
.asEagerSingleton() eager eager
.in(Singleton.class) eager lazy
.in(Scopes.SINGLETON) eager lazy

 

Guice eagerly creates singleton instances only for the modules that are defined as singleton.

@SessionScoped  and @RequestedScoped scope functionality and behavior is the same as Spring in Guice, and it will only be applicable when used in a web application. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.76.72