com.google.inject
Interface Injector


public interface Injector

Fulfills requests for the object instances that make up your application, always ensuring that these instances are properly injected before they are returned. The Injector is the heart of the Guice framework, although you don't typically interact with it directly very often. This "behind-the-scenes" operation is what distinguishes the dependency injection pattern from its cousin, service locator.

The Injector API has a few additional features: it allows pre-constructed instances to have their fields and methods injected and offers programmatic introspection to support tool development.

Contains several default bindings:

Injectors are created using the facade class Guice.


Method Summary
<T> List<Binding<T>>
findBindingsByType(TypeLiteral<T> type)
          Finds all bindings to the given type.
<T> Binding<T>
getBinding(Key<T> key)
          Gets a binding for the given key, or null if no binding for this key is found.
 Map<Key<?>,Binding<?>> getBindings()
          Gets all explicit bindings.
<T> T
getInstance(Class<T> type)
          Returns the appropriate instance for the given type; equivalent to getProvider(type).get().
<T> T
getInstance(Key<T> key)
          Returns the appropriate instance for the given injection key; equivalent to getProvider(key).get().
<T> Provider<T>
getProvider(Class<T> type)
          Returns the provider used to obtain instances for the given injection key.
<T> Provider<T>
getProvider(Key<T> key)
          Returns the provider used to obtain instances for the given injection key.
 void injectMembers(Object o)
          Injects dependencies into the fields and methods of an existing object.
 

Method Detail

injectMembers

void injectMembers(Object o)
Injects dependencies into the fields and methods of an existing object. Ignores the presence or absence of an injectable constructor.

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.


getBindings

Map<Key<?>,Binding<?>> getBindings()
Gets all explicit bindings. This method is part of the Injector Introspection API and is primarily intended for use by tools.


getBinding

<T> Binding<T> getBinding(Key<T> key)
Gets a binding for the given key, or null if no binding for this key is found. This method is part of the Injector Introspection API and is primarily intended for use by tools.


findBindingsByType

<T> List<Binding<T>> findBindingsByType(TypeLiteral<T> type)
Finds all bindings to the given type. This method is part of the Injector Introspection API and is primarily intended for use by tools.


getProvider

<T> Provider<T> getProvider(Key<T> key)
Returns the provider used to obtain instances for the given injection key. When feasible, it's generally preferable to avoid using this method, in favor of having Guice inject your dependencies ahead of time.


getProvider

<T> Provider<T> getProvider(Class<T> type)
Returns the provider used to obtain instances for the given injection key. When feasible, it's generally preferable to avoid using this method, in favor of having Guice inject your dependencies ahead of time.


getInstance

<T> T getInstance(Key<T> key)
Returns the appropriate instance for the given injection key; equivalent to getProvider(key).get(). When feasible, it's generally preferable to avoid using this method, in favor of having Guice inject your dependencies ahead of time.


getInstance

<T> T getInstance(Class<T> type)
Returns the appropriate instance for the given type; equivalent to getProvider(type).get(). When feasible, it's generally preferable to avoid using this method, in favor of having Guice inject your dependencies ahead of time.