Google Guice – Just-in-time Bindings
Google Guice – Just-in-time Bindings
As bindings are defined in Binding Module, Guice uses themwhenever it needs to inject dependencies. In case bindings arenot present, it can attempt to create just-in-time bindings.Bindings present in the binding module are called Explicitbindings and are of higher precedence whereas just-in-timebindings are called Implicit bindings. Note that if bothtype of bindings are present, explicit bindings are consideredfor mapping.
The examples for three types of Just-in-time bindings are givenbelow −
| SR.NO. | BINDING TYPE & DESCRIPTION |
|---|---|
| 1 | Non-private, No-argument constructors are eligible for just-in-time bindings. Another way is to annotate a constructor with @Inject annotation. |
| 2 | @ImplementatedBy annotation tells the guice about the implementation class. No binding is required in Binding Module in such a case. |
| 3 | @ProvidedBy annotation tells the guice about the provider of implementation class. No binding is required in Binding Module in such a case. |
Comments
Post a Comment