public abstract class ObjectGraph extends Object
The following injection features are supported:
@Inject
-annotated constructor. Classes that have fields
injected may omit the @Inject
annotation if they have a public
no-arguments constructor.
@Provides
method parameters.
@Provides
methods annotated @Singleton
.
@Singleton
.
Provider
s.
MembersInjector
s.
The following injection features are not currently supported:
Modifier and Type | Method and Description |
---|---|
static ObjectGraph |
create(Object... modules)
Returns a new dependency graph using the @
Module -annotated modules. |
abstract <T> T |
get(Class<T> type)
Returns an instance of
type . |
abstract <T> T |
inject(T instance)
Injects the members of
instance , including injectable members
inherited from its supertypes. |
abstract void |
injectStatics()
Injects the static fields of the classes listed in the object graph's
staticInjections property. |
abstract ObjectGraph |
plus(Object... modules)
Returns a new object graph that includes all of the objects in this graph,
plus additional objects in the @
Module -annotated
modules. |
abstract void |
validate()
Do runtime graph problem detection.
|
public abstract <T> T get(Class<T> type)
type
.IllegalArgumentException
- if type
is not one of this object
graph's injectable types
.public abstract <T> T inject(T instance)
instance
, including injectable members
inherited from its supertypes.IllegalArgumentException
- if the runtime type of instance
is
not one of this object graph's injectable types
.public abstract ObjectGraph plus(Object... modules)
Module
-annotated
modules. This graph is a subgraph of the returned graph.
The current graph is not modified by this operation: its objects and the dependency links between them are unchanged. But this graph's objects may be shared by both graphs. For example, the singletons of this graph may be injected and used by the returned graph.
This does not inject any members or validate the graph.
See create(java.lang.Object...)
for guidance on injection and validation.
public abstract void validate()
IllegalStateException
- if this graph has problems.public abstract void injectStatics()
staticInjections
property.public static ObjectGraph create(Object... modules)
Module
-annotated modules.
This does not inject any members. Most applications
should call injectStatics()
to inject static members and inject(T)
or get get(Class)
to inject instance members when this
method has returned.
This does not validate the graph. Rely on build time
tools for graph validation, or call validate()
to find problems in
the graph at runtime.
Copyright © 2014 Square, Inc.. All Rights Reserved.