|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.directwebremoting.guice.BindUtil
public class BindUtil
Binding utilities for creating ad hoc providers. These come in two flavors,
constructor and factory method. In both cases, you can specify additional
methods to inject after creation by chaining calls to
injecting(methodName, paramKeys)
.
Each method has two variants, one with a Binder
parameter and one
without. The former reports construction errors via the binder (so more than
one error can be reported), the latter throws a runtime exception immediately,
preventing further error reporting.
Some examples:
bind(SomeInterface.class) .toProvider( .fromConstructor(LegacyImpl.class, Key.get(String.class, MyAnnotation.class)) .injecting("configure", Key.get(Configuration.class)));This binds
SomeInterface
to a provider that uses the
LegacyImpl
constructor with a single String parameter.
That parameter is injected as if it had been marked with @MyAnnotation
.
It also calls the LegacyImpl.configure
method with an injected
instance of Configuration
.
bind(SomeInterface.class) .toProvider( .fromFactoryMethod(SomeInterface.class, LegacyFactory.class, "newSomeInterface", Key.get(String.class, MyAnnotation.class)));This binds
SomeInterface
to a provider that calls a factory method
newSomeInterface
of LegacyFactory
with a single string parameter,
which is injected as if it were marked with @MyAnnotation
. If the
method is not static, an instance of LegacyFactory
is created by injection
and used to call the method.
Nested Class Summary | |
---|---|
static interface |
BindUtil.BindingProvider<T>
For fluent-style decoration with one or more method bindings when using fromConstructor(java.lang.Class . |
Constructor Summary | |
---|---|
BindUtil()
|
Method Summary | ||
---|---|---|
static
|
fromConstructor(com.google.inject.Binder binder,
java.lang.Class<T> type,
com.google.inject.Key... keys)
Creates a chainable provider that constructs an instance of the given type given a list of constructor parameter types, specified as Guice keys. |
|
static
|
fromConstructor(java.lang.Class<T> type,
com.google.inject.Key... keys)
Creates a chainable provider that constructs an instance of the given type given a list of constructor parameter types, specified as Guice keys. |
|
static
|
fromFactoryMethod(com.google.inject.Binder binder,
java.lang.Class<T> providedType,
java.lang.Class<?> factoryType,
java.lang.String methodName,
com.google.inject.Key... keys)
Creates a chainable provider that constructs an instance of providedType
using a factory method defined by factoryType , methodName ,
and a list of method parameter types specified as Guice keys. |
|
static
|
fromFactoryMethod(com.google.inject.Binder binder,
java.lang.Class<T> providedType,
com.google.inject.Key<?> factoryKey,
java.lang.String methodName,
com.google.inject.Key... keys)
Creates a chainable provider that constructs an instance of providedType by
calling method methodName of the type in factoryKey with
method parameter types specified as Guice keys. |
|
static
|
fromFactoryMethod(java.lang.Class<T> providedType,
java.lang.Class<?> factoryType,
java.lang.String methodName,
com.google.inject.Key... keys)
Creates a chainable provider that constructs an instance of providedType
using a factory method defined by factoryType , methodName ,
and a list of method parameter types specified as Guice keys. |
|
static
|
fromFactoryMethod(java.lang.Class<T> providedType,
com.google.inject.Key<?> factoryKey,
java.lang.String methodName,
com.google.inject.Key... keys)
Creates a chainable provider that constructs an instance of providedType by
calling method methodName of the type in factoryKey with
method parameter types specified as Guice keys. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BindUtil()
Method Detail |
---|
public static <T> BindUtil.BindingProvider<T> fromConstructor(java.lang.Class<T> type, com.google.inject.Key... keys)
public static <T> BindUtil.BindingProvider<T> fromConstructor(com.google.inject.Binder binder, java.lang.Class<T> type, com.google.inject.Key... keys)
binder
to be thrown at the end of all binding.
public static <T> BindUtil.BindingProvider<T> fromFactoryMethod(java.lang.Class<T> providedType, java.lang.Class<?> factoryType, java.lang.String methodName, com.google.inject.Key... keys)
providedType
using a factory method defined by factoryType
, methodName
,
and a list of method parameter types specified as Guice keys. If the
method is not static an instance of the factory type is created and injected.
Construction errors are thrown immediately.
public static <T> BindUtil.BindingProvider<T> fromFactoryMethod(com.google.inject.Binder binder, java.lang.Class<T> providedType, java.lang.Class<?> factoryType, java.lang.String methodName, com.google.inject.Key... keys)
providedType
using a factory method defined by factoryType
, methodName
,
and a list of method parameter types specified as Guice keys. If the
method is not static an instance of the factory type is created and injected.
Construction errors are passed to binder
to be thrown at the end
of all binding.
public static <T> BindUtil.BindingProvider<T> fromFactoryMethod(java.lang.Class<T> providedType, com.google.inject.Key<?> factoryKey, java.lang.String methodName, com.google.inject.Key... keys)
providedType
by
calling method methodName
of the type in factoryKey
with
method parameter types specified as Guice keys. If the method is not static
an instance is created and injected using the factory key.
Construction errors are thrown immediately.
public static <T> BindUtil.BindingProvider<T> fromFactoryMethod(com.google.inject.Binder binder, java.lang.Class<T> providedType, com.google.inject.Key<?> factoryKey, java.lang.String methodName, com.google.inject.Key... keys)
providedType
by
calling method methodName
of the type in factoryKey
with
method parameter types specified as Guice keys. If the method is not static
an instance is created and injected using the factory key.
Construction errors are passed to binder
to be thrown at the end
of all binding.
|
Copyright ? 2005 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |