com.twitter.common.inject
Class Bindings

java.lang.Object
  extended by com.twitter.common.inject.Bindings

public final class Bindings
extends Object

A utility that helps with guice bindings.


Nested Class Summary
static interface Bindings.BindHelper<T>
          A guice binding helper that allows for any combination of Class, TypeLiteral or Key binding without forcing guiced implementation to provide all the overloaded binding methods they would otherwise have to.
 
Method Summary
static
<T> Bindings.BindHelper<T>
binderFor(Key<T> key)
          Creates a BindHelper for the given binding key that can be used to bind a single instance.
static
<T> Bindings.BindHelper<T>
multiBinderFor(Class<T> type)
          Creates a BindHelper for the given type that can be used to add a binding of to a set.
static void requireBinding(Binder binder, Class<?> required)
          Equivalent to calling requireBinding(binder, Key.get(required)).
static void requireBinding(Binder binder, Key<?> required)
          Registers required as non-optional dependency in the Injector associated with binder.
static void requireNamedBinding(Binder binder, Class<?> required, String namedKey)
          Equivalent to calling requireBinding(binder, Key.get(required, Names.named(namedKey))).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

requireNamedBinding

public static void requireNamedBinding(Binder binder,
                                       Class<?> required,
                                       String namedKey)
Equivalent to calling requireBinding(binder, Key.get(required, Names.named(namedKey))).


requireBinding

public static void requireBinding(Binder binder,
                                  Class<?> required)
Equivalent to calling requireBinding(binder, Key.get(required)).


requireBinding

public static void requireBinding(Binder binder,
                                  Key<?> required)
Registers required as non-optional dependency in the Injector associated with binder.

Parameters:
binder - a guice binder to require bindings against
required - the dependency that is required

binderFor

public static <T> Bindings.BindHelper<T> binderFor(Key<T> key)
Creates a BindHelper for the given binding key that can be used to bind a single instance.

Type Parameters:
T - the type the returned BindHelper can be used to bind implementations for
Parameters:
key - the binding key the returned BindHelper can be use to bind implementations for
Returns:
a BindHelper that can be used to bind an implementation with

multiBinderFor

public static <T> Bindings.BindHelper<T> multiBinderFor(Class<T> type)
Creates a BindHelper for the given type that can be used to add a binding of to a set.

Type Parameters:
T - the type the returned BindHelper can be used to bind implementations for
Parameters:
type - the type the returned BindHelper can be use to bind implementations for
Returns:
a BindHelper that can be used to bind an implementation with