Contains several default bindings:
Injector instance itself
Provider<T> for each binding of type T
java.util.logging.Logger for the class being injected
Stage in which the Injector was created
Guice.
An injector can also inject the dependencies of
already-constructed instances. This can be used to interoperate with objects created by other
frameworks or services.
Injectors can be hierarchical. Child injectors inherit
the configuration of their parent injectors, but the converse does not hold.
The injector's internal bindings are available for introspection. This
enables tools and extensions to operate on an injector reflectively.
| Modifier and Type | Method and Description |
|---|---|
| public Injector | createChildInjector(Iterable<? extends Module> modules)
Returns a new injector that inherits all state from this injector. |
| public Injector | createChildInjector(Module... modules)
Returns a new injector that inherits all state from this injector. |
| public <T> List | |
| public Map | |
| public Map | getAllMembersInjectorInjectionPoints()
Returns the injection points created for calls to |
| public <T> Binding | |
| public <T> Binding | |
| public Map | |
| public List | |
| public <T> Binding | |
| public <T> T | getInstance(Key<T> key)
Returns the appropriate instance for the given injection key; equivalent to |
| public <T> T | getInstance(Class<T> type)
Returns the appropriate instance for the given injection type; equivalent to |
| public <T> MembersInjector | getMembersInjector(TypeLiteral<T>
type to get members injector for typeLiteral)Returns the members injector used to inject dependencies into methods and fields on instances
of the given type |
| public <T> MembersInjector | getMembersInjector(Class<T>
type to get members injector for type)Returns the members injector used to inject dependencies into methods and fields on instances
of the given type |
| public Injector | |
| public <T> Provider | |
| public <T> Provider | |
| public Map | |
| public Set | |
| public void | injectMembers(Object
to inject members on instance)Injects dependencies into the fields and methods of |
| createChildInjector | back to summary |
|---|---|
| public Injector createChildInjector(Iterable<? extends Module> modules) Returns a new injector that inherits all state from this injector. All bindings, scopes, interceptors and type converters are inherited -- they are visible to the child injector. Elements of the child injector are not visible to its parent. Just-in-time bindings created for child injectors will be created in an ancestor injector whenever possible. This allows for scoped instances to be shared between injectors. Use explicit bindings to prevent bindings from being shared with the parent injector. Optional injections in just-in-time bindings (created in the parent injector) may be silently ignored if the optional dependencies are from the child injector. No key may be bound by both an injector and one of its ancestors. This includes just-in-time
bindings. The lone exception is the key for When using hierarchical injectors (via
| |
| createChildInjector | back to summary |
|---|---|
| public Injector createChildInjector(Module... modules) Returns a new injector that inherits all state from this injector. All bindings, scopes, interceptors and type converters are inherited -- they are visible to the child injector. Elements of the child injector are not visible to its parent. Just-in-time bindings created for child injectors will be created in an ancestor injector whenever possible. This allows for scoped instances to be shared between injectors. Use explicit bindings to prevent bindings from being shared with the parent injector. No key may be bound by both an injector and one of its ancestors. This includes just-in-time
bindings. The lone exception is the key for
| |
| findBindingsByType | back to summary |
|---|---|
| public <T> List Returns all explicit bindings for This method is part of the Guice SPI and is intended for use by tools and extensions. | |
| getAllBindings | back to summary |
|---|---|
| public Map Returns a snapshot of this injector's bindings, both explicit and
just-in-time. The returned map is immutable; it contains only the bindings that were
present when The returned map does not include bindings inherited from a This method is part of the Guice SPI and is intended for use by tools and extensions.
| |
| getAllMembersInjectorInjectionPoints | back to summary |
|---|---|
| public Map Returns the injection points created for calls to This excludes any injection points from elements (which are accessible from each element via
the SPI), unless The returned multimap does not include data inherited from a This method is part of the Guice SPI and is intended for use by tools and extensions.
| |
| getBinding | back to summary |
|---|---|
| public <T> Binding Returns the binding for the given injection key. This will be an explicit bindings if the key was bound explicitly by a module, or an implicit binding otherwise. The implicit binding will be created if necessary. This method is part of the Guice SPI and is intended for use by tools and extensions.
| |
| getBinding | back to summary |
|---|---|
| public <T> Binding Returns the binding for the given type. This will be an explicit bindings if the injection key was bound explicitly by a module, or an implicit binding otherwise. The implicit binding will be created if necessary. This method is part of the Guice SPI and is intended for use by tools and extensions.
| |
| getBindings | back to summary |
|---|---|
| public Map Returns this injector's explicit bindings. The returned map does not include bindings inherited from a This method is part of the Guice SPI and is intended for use by tools and extensions. | |
| getElements | back to summary |
|---|---|
| public List Returns the elements that make up this injector. Note that not all kinds of elements are returned. The returned list does not include elements inherited from a The returned list is immutable; it contains only the elements that were present when The returned list does not include data inherited from a This method is part of the Guice SPI and is intended for use by tools and extensions.
| |
| getExistingBinding | back to summary |
|---|---|
| public <T> Binding Returns the binding if it already exists, or null if does not exist. Unlike This method is part of the Guice SPI and is intended for use by tools and extensions.
| |
| getInstance | back to summary |
|---|---|
| public <T> T getInstance(Key<T> key) Returns the appropriate instance for the given injection key; equivalent to
| |
| getInstance | back to summary |
|---|---|
| public <T> T getInstance(Class<T> type) Returns the appropriate instance for the given injection type; equivalent to
| |
| getMembersInjector | back to summary |
|---|---|
| public <T> MembersInjector Returns the members injector used to inject dependencies into methods and fields on instances
of the given type
| |
| getMembersInjector | back to summary |
|---|---|
| public <T> MembersInjector Returns the members injector used to inject dependencies into methods and fields on instances
of the given type
| |
| getParent | back to summary |
|---|---|
| public Injector getParent() Returns this injector's parent, or
| |
| getProvider | back to summary |
|---|---|
| public <T> Provider Returns the provider used to obtain instances for the given injection key. When feasible, avoid using this method, in favor of having Guice inject your dependencies ahead of time.
| |
| getProvider | back to summary |
|---|---|
| public <T> Provider Returns the provider used to obtain instances for the given type. When feasible, avoid using this method, in favor of having Guice inject your dependencies ahead of time.
| |
| getScopeBindings | back to summary |
|---|---|
| public Map Returns a map containing all scopes in the injector. The maps keys are scoping annotations like
This method is part of the Guice SPI and is intended for use by tools and extensions.
| |
| getTypeConverterBindings | back to summary |
|---|---|
| public Set Returns a set containing all type converter bindings in the injector. The returned set is immutable. This method is part of the Guice SPI and is intended for use by tools and extensions.
| |
| injectMembers | back to summary |
|---|---|
| public void injectMembers(Object instance) Injects dependencies into the fields and methods of Whenever Guice creates an instance, it performs this injection automatically (after first performing constructor injection), so if you're able to let Guice create all your objects for you, you'll never need to use this method.
| |