| java.lang.Object org.directwebremoting.guice.BindUtil
BindUtil | public class BindUtil (Code) | | 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
BindingProvider.injecting 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.
author: Tim Peierls [tim at peierls dot net] |
Inner Class :public interface BindingProvider extends Provider<T> | |
Method Summary | |
public static BindingProvider<T> | fromConstructor(Class<T> type, 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. | public static BindingProvider<T> | fromConstructor(Binder binder, Class<T> type, 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. | public static BindingProvider<T> | fromFactoryMethod(Class<T> providedType, Class> factoryType, String methodName, 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. | public static BindingProvider<T> | fromFactoryMethod(Binder binder, Class<T> providedType, Class> factoryType, String methodName, 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. | public static BindingProvider<T> | fromFactoryMethod(Class<T> providedType, Key> factoryKey, String methodName, 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. | public static BindingProvider<T> | fromFactoryMethod(Binder binder, Class<T> providedType, Key> factoryKey, String methodName, 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. |
fromConstructor | public static BindingProvider<T> fromConstructor(Class<T> type, Key>... keys)(Code) | | Creates a chainable provider that constructs an instance of the
given type given a list of constructor parameter types, specified
as Guice keys. Construction errors are thrown immediately.
|
fromConstructor | public static BindingProvider<T> fromConstructor(Binder binder, Class<T> type, Key>... keys)(Code) | | Creates a chainable provider that constructs an instance of the
given type given a list of constructor parameter types, specified
as Guice keys. Construction errors are passed to
binder to be thrown at the end of all binding.
|
fromFactoryMethod | public static BindingProvider<T> fromFactoryMethod(Class<T> providedType, Class> factoryType, String methodName, Key>... keys)(Code) | | 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. If the
method is not static an instance of the factory type is created and injected.
Construction errors are thrown immediately.
|
fromFactoryMethod | public static BindingProvider<T> fromFactoryMethod(Binder binder, Class<T> providedType, Class> factoryType, String methodName, Key>... keys)(Code) | | 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. 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.
|
fromFactoryMethod | public static BindingProvider<T> fromFactoryMethod(Class<T> providedType, Key> factoryKey, String methodName, Key>... keys)(Code) | | 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. If the method is not static
an instance is created and injected using the factory key.
Construction errors are thrown immediately.
|
fromFactoryMethod | public static BindingProvider<T> fromFactoryMethod(Binder binder, Class<T> providedType, Key> factoryKey, String methodName, Key>... keys)(Code) | | 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. 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.
|
|
|