@Override public Object instantiate(DAGNode<Component, Dependency> node) throws InjectionException { return container.makeInstantiator(node).instantiate(); } }
@Override public Object instantiate(DAGNode<Component, Dependency> node) throws InjectionException { return container.makeInstantiator(node).instantiate(); } }
/** * Get a provider that, when invoked, will return an instance of the component represented * by a graph. * * * @param node The graph. * @return A provider to instantiate {@code graph}. * @see #makeInstantiator(DAGNode, SetMultimap) */ public Instantiator makeInstantiator(DAGNode<Component, Dependency> node) { return makeInstantiator(node, ImmutableSetMultimap.<DAGNode<Component, Dependency>, DAGEdge<Component, Dependency>>of()); }
@Nullable @Override public Instantiator apply(@Nullable Desire input) { for (DAGEdge<Component,Dependency> edge: edges) { if (edge.getLabel().getInitialDesire().equals(input)) { return makeInstantiator(edge.getTail(), backEdges); } } return null; } }
@Override @SuppressWarnings("unchecked") public <T> T getInstance(Annotation qualifier, Class<T> type) throws InjectionException { // All Provider cache access, graph resolution, etc. occur // within this exclusive lock so we know everything is thread safe // albeit in a non-optimal way. synchronized(this) { Desire desire = Desires.create(qualifier, type, false); Predicate<Dependency> pred = Dependency.hasInitialDesire(desire); // check if the desire is already in the graph DAGEdge<Component, Dependency> resolved = solver.getGraph().getOutgoingEdgeWithLabel(pred); // The edge is only non-null if instantiate() has been called before, // it may be present in the graph at a deeper node. If that's the case // it will be properly merged after regenerating the graph at the root context. if (resolved == null) { logger.info("Must resolve desire: {}", desire); solver.resolve(desire); resolved = solver.getGraph().getOutgoingEdgeWithLabel(pred); } // Check if the provider for the resolved node is in our cache DAGNode<Component, Dependency> resolvedNode = resolved.getTail(); return type.cast(instantiator.makeInstantiator(resolvedNode, solver.getBackEdges()).instantiate()); } } }