public class DependencySolver extends Object
DependencySolver is a utility for resolving Desires into a dependency graph, where nodes are shared when permitted by a Satisfaction's dependency configuration. It supports qualified and context-aware injection, and just-in-time injection if the type has an injectable constructor.
The conceptual binding function used by this solver is represented as a list
of prioritized functions
. Functions at the start of
the list are used first, which makes it easy to provide custom functions that
override default behaviors.
This solver does not support cyclic dependencies because of the possibility that a context later on might activate a bind rule that breaks the cycle. To ensure termination, it has a maximum context depth that is configurable.
DefaultInjector
Modifier and Type | Field and Description |
---|---|
static Component |
ROOT_SATISFACTION |
Modifier and Type | Method and Description |
---|---|
DAGNode<Component,Dependency> |
getBackEdge(DAGNode<Component,Dependency> parent,
Desire desire)
Get the back edge for a particular node and desire, if one exists.
|
com.google.common.collect.SetMultimap<DAGNode<Component,Dependency>,DAGEdge<Component,Dependency>> |
getBackEdges()
Get the map of back-edges for circular dependencies.
|
DAGNode<Component,Dependency> |
getGraph()
Get the current full dependency graph.
|
DAGNode<Component,Dependency> |
getRootNode()
Deprecated.
Use
getGraph() instead. |
static InjectionContext |
initialContext()
Get an initial injection context.
|
static DependencySolverBuilder |
newBuilder()
Create a new dependency solver builder.
|
void |
resolve(Desire desire)
Update the dependency graph to include the given desire.
|
DAGNode<Component,Dependency> |
rewrite(DAGNode<Component,Dependency> graph)
Rewrite a dependency graph using the rules in this solver.
|
static DAGNode<Component,Dependency> |
rootNode()
Get a singleton root node for a dependency graph.
|
public static final Component ROOT_SATISFACTION
public static InjectionContext initialContext()
public static DAGNode<Component,Dependency> rootNode()
public static DependencySolverBuilder newBuilder()
public DAGNode<Component,Dependency> getGraph()
resolve(Desire)
.public com.google.common.collect.SetMultimap<DAGNode<Component,Dependency>,DAGEdge<Component,Dependency>> getBackEdges()
ProviderBindingFunction
is one of the binding
functions. In such cases, there will be a back edge from the provider node to the actual
node being provided, and this map will report that edge.public DAGNode<Component,Dependency> getBackEdge(DAGNode<Component,Dependency> parent, Desire desire)
null
if no edge exists.getBackEdges()
@Deprecated public DAGNode<Component,Dependency> getRootNode()
getGraph()
instead.public void resolve(Desire desire) throws ResolutionException
desire
- The desire to include in the graphResolutionException
public DAGNode<Component,Dependency> rewrite(DAGNode<Component,Dependency> graph) throws ResolutionException
Graph rewrite walks the graph, looking for nodes to rewrite. If the desire that leads to a node is matched by a trigger binding function, then it is resolved using the binding functions and replaced with the resulting (merged) node. Rewriting proceeds from the root down, but does not consider the children of nodes generated by the rewriting process.
graph
- The graph to rewrite.ResolutionException
Copyright © 2016 GroupLens Research. All rights reserved.