public abstract class AbstractModule extends Objectimplements Module
Modules which reduces repetition and results in a more readable configuration. Simply extend this class, implement
configure(), and call the inherited methods which mirror those found in
Binder. For example:
public class MyModule extends AbstractModule {
protected void configure() {
bind(Service.class).to(ServiceImpl.class).in(Singleton.class);
bind(CreditCardPaymentService.class);
bind(PaymentService.class).to(CreditCardPaymentService.class);
bindConstant().annotatedWith(Names.named("port")).to(8080);
}
}
| Constructor and Description |
|---|
AbstractModule()
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addError(Message
|
protected void |
addError(String
|
protected void |
addError(Throwable
|
protected <T> AnnotatedBindingBuilder |
bind(Class
|
protected <T> LinkedBindingBuilder |
bind(Key
|
protected <T> AnnotatedBindingBuilder |
bind(TypeLiteral
|
protected AnnotatedConstantBindingBuilder |
bindConstant()
|
protected Binder |
binder()
Gets direct access to the underlying
Binder.
|
protected void |
bindInterceptor(Matcher
|
protected void |
bindListener(Matcher
|
protected void |
bindListener(Matcher
|
protected void |
bindScope(Class
|
protected abstract void |
configure()
Configures a
Binder via the exposed methods.
|
void |
configure(Binder
Contributes bindings and other configurations for this module to
binder.
|
protected void |
convertToTypes(Matcher
|
protected Stage |
currentStage()
|
protected <T> MembersInjector |
getMembersInjector(Class
|
protected <T> MembersInjector |
getMembersInjector(TypeLiteral
|
protected <T> Provider |
getProvider(Class
|
protected <T> Provider |
getProvider(Key
|
protected void |
install(Module
|
protected void |
requestInjection(Object
|
protected void |
requestStaticInjection(Class
|
protected void |
requireBinding(Class
Adds a dependency from this module to
type.
|
protected void |
requireBinding(Key
Adds a dependency from this module to
key.
|
public final void configure(Binderbuilder)
Module
binder.
Do not invoke this method directly to install submodules. Instead use Binder, which ensures that provider methods are discovered.
protected abstract void configure()
Binder via the exposed methods.
protected Binderbinder()
Binder.
protected void bindScope(Class<? extends Annotation > scopeAnnotation, Scope scope)
Binder.bindScope(Class, Scope)
protected <T> LinkedBindingBuilder<T> bind(Key <T> key)
Binder.bind(Key)
protected <T> AnnotatedBindingBuilder<T> bind(TypeLiteral <T> typeLiteral)
Binder.bind(TypeLiteral)
protected <T> AnnotatedBindingBuilder<T> bind(Class <T> clazz)
Binder.bind(Class)
protected AnnotatedConstantBindingBuilderbindConstant()
Binder.bindConstant()
protected void install(Modulemodule)
Binder.install(Module)
protected void addError(Stringmessage, Object ... arguments)
Binder.addError(String, Object[])
protected void addError(Throwablet)
Binder.addError(Throwable)
protected void addError(Messagemessage)
Binder.addError(Message)
protected void requestInjection(Objectinstance)
Binder.requestInjection(Object)
protected void requestStaticInjection(Class<?>... types)
Binder.requestStaticInjection(Class[])
protected void bindInterceptor(Matcher<? super Class <?>> classMatcher, Matcher <? super Method > methodMatcher, org .aopalliance .intercept .MethodInterceptor ... interceptors)
protected void requireBinding(Key<?> key)
key. When the injector is created, Guice will report an error if
key cannot be injected. Note that this requirement may be satisfied by implicit binding, such as a public no-arguments constructor.
protected void requireBinding(Class<?> type)
type. When the injector is created, Guice will report an error if
type cannot be injected. Note that this requirement may be satisfied by implicit binding, such as a public no-arguments constructor.
protected <T> Provider<T> getProvider(Key <T> key)
Binder.getProvider(Key)
protected <T> Provider<T> getProvider(Class <T> type)
Binder.getProvider(Class)
protected void convertToTypes(Matcher<? super TypeLiteral <?>> typeMatcher, TypeConverter converter)
protected StagecurrentStage()
Binder.currentStage()
protected <T> MembersInjector<T> getMembersInjector(Class <T> type)
Binder.getMembersInjector(Class)
protected <T> MembersInjector<T> getMembersInjector(TypeLiteral <T> type)
Binder.getMembersInjector(TypeLiteral)
protected void bindListener(Matcher<? super TypeLiteral <?>> typeMatcher, TypeListener listener)
protected void bindListener(Matcher<? super Binding <?>> bindingMatcher, ProvisionListener ... listener)
Binder.bindListener(Matcher, ProvisionListener...)