Package com.google.inject
Interface Binding<T>
-
- Type Parameters:
T
- the bound type. The injected is always assignable to this type.
- All Superinterfaces:
Element
- All Known Subinterfaces:
ConstructorBinding<T>
,ConvertedConstantBinding<T>
,ExposedBinding<T>
,InstanceBinding<T>
,LinkedKeyBinding<T>
,ProviderBinding<T>
,ProviderInstanceBinding<T>
,ProviderKeyBinding<T>
,UntargettedBinding<T>
- All Known Implementing Classes:
BindingImpl
public interface Binding<T> extends Element
A mapping from a key (type and optional annotation) to the strategy for getting instances of the type. This interface is part of the introspection API and is intended primarily for use by tools.Bindings are created in several ways:
- Explicitly in a module, via
bind()
andbindConstant()
statements:bind(Service.class).annotatedWith(Red.class).to(ServiceImpl.class); bindConstant().annotatedWith(ServerHost.class).to(args[0]);
- Implicitly by the Injector by following a type's
pointer
annotations
or by using itsannotated
or default constructor. - By converting a bound instance to a different type.
- For
providers
, by delegating to the binding for the provided type.
They exist on both modules and on injectors, and their behaviour is different for each:
- Module bindings are incomplete and cannot be used to provide instances. This is because the applicable scopes and interceptors may not be known until an injector is created. From a tool's perspective, module bindings are like the injector's source code. They can be inspected or rewritten, but this analysis must be done statically.
- Injector bindings are complete and valid and can be used to provide instances. From a tools' perspective, injector bindings are like reflection for an injector. They have full runtime information, including the complete graph of injections necessary to satisfy a binding.
- Author:
- crazybob@google.com (Bob Lee), jessewilson@google.com (Jesse Wilson)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <V> V
acceptScopingVisitor(BindingScopingVisitor<V> visitor)
Accepts a scoping visitor.<V> V
acceptTargetVisitor(BindingTargetVisitor<? super T,V> visitor)
Accepts a target visitor.Key<T>
getKey()
Returns the key for this binding.Provider<T>
getProvider()
Returns the scoped provider guice uses to fulfill requests for this binding.-
Methods inherited from interface com.google.inject.spi.Element
acceptVisitor, applyTo, getSource
-
-
-
-
Method Detail
-
getProvider
Provider<T> getProvider()
Returns the scoped provider guice uses to fulfill requests for this binding.- Throws:
UnsupportedOperationException
- when invoked on aBinding
created viaElements.getElements(com.google.inject.Module...)
. This method is only supported onBinding
s returned from an injector.
-
acceptTargetVisitor
<V> V acceptTargetVisitor(BindingTargetVisitor<? super T,V> visitor)
Accepts a target visitor. Invokes the visitor method specific to this binding's target.- Parameters:
visitor
- to call back on- Since:
- 2.0
-
acceptScopingVisitor
<V> V acceptScopingVisitor(BindingScopingVisitor<V> visitor)
Accepts a scoping visitor. Invokes the visitor method specific to this binding's scoping.- Parameters:
visitor
- to call back on- Since:
- 2.0
-
-