com.google.inject
Interface Binder


public interface Binder

Collects configuration information (primarily bindings) which will be used to create an Injector. Guice provides this object to your application's Modules so they may each contribute their own bindings.

The bindings contributed by Modules define how the Injector resolves dependencies. A Key consisting of a type and optional annotation uniquely identifies a binding within an Injector.

You may bind from a key to:

In addition, a binding may have an associated scope, such as Scopes.SINGLETON, and singleton bindings may specify eager or lazy initialization.

See the users' guide appendix, "How the Injector resolves injection requests," to better understand binding resolution.

After an Injector has been created, its bindings may be examined using methods like Injector.getBinding(Key), but this read-only Binding type is not used when creating the bindings.


Method Summary
 void addError(java.lang.String message, java.lang.Object... arguments)
          Records an error message which will be presented to the user at a later time.
 void addError(java.lang.Throwable t)
          Records an exception, the full details of which will be logged, and the message of which will be presented to the user at a later time.
<T> AnnotatedBindingBuilder<T>
bind(java.lang.Class<T> type)
          Creates a binding to a type.
<T> LinkedBindingBuilder<T>
bind(Key<T> key)
          Creates a binding to a key.
<T> AnnotatedBindingBuilder<T>
bind(TypeLiteral<T> typeLiteral)
          Creates a binding to a type.
 AnnotatedConstantBindingBuilder bindConstant()
          Binds a constant value to an annotation.
 void bindInterceptor(Matcher<? super java.lang.Class<?>> classMatcher, Matcher<? super java.lang.reflect.Method> methodMatcher, org.aopalliance.intercept.MethodInterceptor... interceptors)
          Binds a method interceptor to methods matched by class and method matchers.
 void bindScope(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, Scope scope)
          Binds a scope to an annotation.
 Stage currentStage()
          Gets the current stage.
 void install(Module module)
          Uses the given module to configure more bindings.
 void requestStaticInjection(java.lang.Class<?>... types)
          Upon successful creation, the Injector will inject static fields and methods in the given classes.
 

Method Detail

bindInterceptor

void bindInterceptor(Matcher<? super java.lang.Class<?>> classMatcher,
                     Matcher<? super java.lang.reflect.Method> methodMatcher,
                     org.aopalliance.intercept.MethodInterceptor... interceptors)
Binds a method interceptor to methods matched by class and method matchers.

Parameters:
classMatcher - matches classes the interceptor should apply to. For example: only(Runnable.class).
methodMatcher - matches methods the interceptor should apply to. For example: annotatedWith(Transactional.class).
interceptors - to bind

bindScope

void bindScope(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
               Scope scope)
Binds a scope to an annotation.


bind

<T> LinkedBindingBuilder<T> bind(Key<T> key)
Creates a binding to a key.


bind

<T> AnnotatedBindingBuilder<T> bind(TypeLiteral<T> typeLiteral)
Creates a binding to a type.


bind

<T> AnnotatedBindingBuilder<T> bind(java.lang.Class<T> type)
Creates a binding to a type.


bindConstant

AnnotatedConstantBindingBuilder bindConstant()
Binds a constant value to an annotation.


requestStaticInjection

void requestStaticInjection(java.lang.Class<?>... types)
Upon successful creation, the Injector will inject static fields and methods in the given classes.

Parameters:
types - for which static members will be injected

install

void install(Module module)
Uses the given module to configure more bindings.


currentStage

Stage currentStage()
Gets the current stage.


addError

void addError(java.lang.String message,
              java.lang.Object... arguments)
Records an error message which will be presented to the user at a later time. Unlike throwing an exception, this enable us to continue configuring the Injector and discover more errors. Uses String.format(String, Object[]) to insert the arguments into the message.


addError

void addError(java.lang.Throwable t)
Records an exception, the full details of which will be logged, and the message of which will be presented to the user at a later time. If your Module calls something that you worry may fail, you should catch the exception and pass it into this.



Copyright © 2008. All Rights Reserved.