Package com.google.inject.spi
Class ProvisionListener.ProvisionInvocation<T>
- java.lang.Object
-
- com.google.inject.spi.ProvisionListener.ProvisionInvocation<T>
-
- Enclosing interface:
- ProvisionListener
public abstract static class ProvisionListener.ProvisionInvocation<T> extends java.lang.Object
Encapsulates a single act of provisioning.- Since:
- 4.0
-
-
Constructor Summary
Constructors Constructor Description ProvisionInvocation()
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description abstract Binding<T>
getBinding()
Returns the Binding this is provisioning.abstract java.util.List<DependencyAndSource>
getDependencyChain()
Deprecated.This method is planned for removal in Guice 4.4.abstract T
provision()
Performs the provision, returning the object provisioned.
-
-
-
Method Detail
-
getBinding
public abstract Binding<T> getBinding()
Returns the Binding this is provisioning.You must not call
Provider.get()
on the provider returned byBinding.getProvider()
, otherwise you will get confusing error messages.
-
provision
public abstract T provision()
Performs the provision, returning the object provisioned.
-
getDependencyChain
@Deprecated public abstract java.util.List<DependencyAndSource> getDependencyChain()
Deprecated.This method is planned for removal in Guice 4.4. Some use cases can be replaced by inferring the current chain via ThreadLocals in the listener, other use cases can use the static dependency graph. For example,bindListener(Matchers.any(), new MyListener()); ... private static final class MyListener implements ProvisionListener { private final ThreadLocal<ArrayDeque<Binding<?>>> bindingStack = new ThreadLocal<ArrayDeque<Binding<?>>>() { {@literal @}Override protected ArrayDeque<Binding<?>> initialValue() { return new ArrayDeque<>(); } }; {@literal @}Override public <T> void onProvision(ProvisionInvocation<T> invocation) { bindingStack.get().push(invocation.getBinding()); try { invocation.provision(); } finally { bindingStack.get().pop(); } // Inspect the binding stack... } }
In this example the bindingStack thread local will contain a data structure that is very similar to the data returned by this list. The main differences are that linked keys are not in the stack, but such edges do exist in the static dependency graph (inspectable via
HasDependencies.getDependencies()
), so you could infer some of the missing edges..Returns the dependency chain that led to this object being provisioned.
-
-