|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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:
Injector
instance itself
Provider<T>
for each binding of type T
Logger
for the class being injected
Stage
in which the Injector was created
Guice
.
Method Summary | ||
---|---|---|
|
findBindingsByType(TypeLiteral<T> type)
Finds all bindings to the given type. |
|
|
getBinding(Class<T> type)
Gets a binding for the given type, or null if no binding for this type is found. |
|
|
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. |
|
|
getInstance(Class<T> type)
Returns the appropriate instance for the given type; equivalent to getProvider(type).get() . |
|
|
getInstance(Key<T> key)
Returns the appropriate instance for the given injection key; equivalent to getProvider(key).get() . |
|
|
getProvider(Class<T> type)
Returns the provider used to obtain instances for the given injection key. |
|
|
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 |
---|
void injectMembers(Object o)
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.
Map<Key<?>,Binding<?>> getBindings()
This method is part of the Injector Introspection API and is primarily intended for use by tools.
<T> Binding<T> getBinding(Key<T> key)
This method is part of the Injector Introspection API and is primarily intended for use by tools.
<T> Binding<T> getBinding(Class<T> type)
This method is part of the Injector Introspection API and is primarily intended for use by tools.
<T> List<Binding<T>> findBindingsByType(TypeLiteral<T> type)
<T> Provider<T> getProvider(Key<T> key)
<T> Provider<T> getProvider(Class<T> type)
<T> T getInstance(Key<T> key)
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.
<T> T getInstance(Class<T> type)
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.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |