
- Guice - Home
- Guice - Overview
- Guice - Environment Setup
- Guice - First Application
- Bindings Examples
- Guice - Linked binding
- Guice - Binding Annotations
- Guice - @Named binding
- Guice - Constant Bindings
- Guice - @Provides Annotation
- Guice - Provider Class
- Guice - Constructor Bindings
- Guice - Inbuilt Bindings
- Guice - Just-in-time Bindings
- Injection Examples
- Guice - Constructor Injection
- Guice - Method Injection
- Guice - Field Injection
- Guice - Optional Injection
- Guice - On-demand Injection
- Miscellaneous Examples
- Guice - Scopes
- Guice - AOP
- Guice Useful Resources
- Guice - Quick Guide
- Guice - Useful Resources
- Guice - Discussion
Guice - Just-In-Time Bindings
Introduction
As bindings are defined in Binding Module, Guice uses them whenever it needs to inject dependencies. In case bindings are not present, it can attempt to create just-in-time bindings. Bindings present in binding module are called explicit bindings and are of higher precedence whereas just-in-time bindings are called implicit bindings. If both type of bindings are present, explicit bindings are considered for mapping.
Types of Just-In-Time Bindings
Following are the examples of three types of Just-in-time bindings.
Binding Type | Description |
---|---|
Injectable Constructors | Non-private, No-argument constructors are eligible for just-in-time bindings. Another way is to annotate a constructor with @Inject annotation. |
@ImplementedBy annotation | @ImplementedBy annotation tells the guice about the implementation class. No binding is required in Binding Module in such a case. |
@ProvidedBy annotation | @ProvidedBy annotation tells the guice about the provider of implementation class. No binding is required in Binding Module in such a case. |
Advertisements