Top Description Fields Constructors Methods
com.google.inject

public abstract Class AbstractModule

extends Object
implements Module
Class Inheritance
All Implemented Interfaces
com.google.inject.Module
Known Direct Subclasses
com.google.inject.internal.RealMultibinder.PermitDuplicatesModule, com.google.inject.util.Modules.OverrideModule
Static Imports
com.google.common.base.Preconditions.checkNotNull, .Preconditions.checkState

AbstractModule is a helper class used to add bindings to the Guice injector.

Simply extend this class, then you can add bindings by either defining @Provides methods (see https://github.com/google/guice/wiki/ProvidesMethods) or implementing configure(), and calling 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);
  }
}
Author
[email protected] (Bob Lee)

Field Summary

Modifier and TypeField and Description
pack-priv Binder

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
addError(String message, Object... arguments)

protected void
protected void
addError(Message message)

protected <T> LinkedBindingBuilder<T>
bind(Key<T> key)

protected <T> AnnotatedBindingBuilder<T>
protected <T> AnnotatedBindingBuilder<T>
protected AnnotatedConstantBindingBuilder
protected Binder
binder()

Gets direct access to the underlying Binder.

protected void
bindInterceptor(Matcher<? super Class<?>> classMatcher, Matcher<? super Method> methodMatcher, MethodInterceptor... interceptors)

protected void
bindListener(Matcher<? super TypeLiteral<?>> typeMatcher, TypeListener listener)

protected void
bindListener(Matcher<? super Binding<?>> bindingMatcher, ProvisionListener... listener)

protected void
bindScope(Class<? extends Annotation> scopeAnnotation, Scope scope)

public final synchronized void
configure(Binder builder)

Implements com.google.inject.Module.configure.

Contributes bindings and other configurations for this module to binder.
protected void
configure()

Configures a Binder via the exposed methods.

protected void
convertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher, TypeConverter converter)

protected Stage
protected <T> MembersInjector<T>
protected <T> MembersInjector<T>
protected <T> Provider<T>
getProvider(Key<T> key)

protected <T> Provider<T>
getProvider(Class<T> type)

protected void
install(Module module)

protected void
protected <T> void
requestInjection(TypeLiteral<T> type, T instance)

protected void
protected void
requireBinding(Key<?> key)

Adds a dependency from this module to key.

protected void
requireBinding(Class<?> type)

Adds a dependency from this module to type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

binderback to summary
pack-priv Binder binder

Constructor Detail

AbstractModuleback to summary
public AbstractModule()

Method Detail

addErrorback to summary
protected void addError(String message, Object... arguments)
See Also
Binder#addError(String, Object[])
addErrorback to summary
protected void addError(Throwable t)
See Also
Binder#addError(Throwable)
addErrorback to summary
protected void addError(Message message)
Since
2.0
See Also
Binder#addError(Message)
bindback to summary
protected <T> LinkedBindingBuilder<T> bind(Key<T> key)
See Also
Binder#bind(Key)
bindback to summary
protected <T> AnnotatedBindingBuilder<T> bind(TypeLiteral<T> typeLiteral)

See Binder#bind(TypeLiteral).

bindback to summary
protected <T> AnnotatedBindingBuilder<T> bind(Class<T> clazz)

See Binder#bind(Class).

bindConstantback to summary
protected AnnotatedConstantBindingBuilder bindConstant()
See Also
Binder#bindConstant()
binderback to summary
protected Binder binder()

Gets direct access to the underlying Binder.

bindInterceptorback to summary
protected void bindInterceptor(Matcher<? super Class<?>> classMatcher, Matcher<? super Method> methodMatcher, MethodInterceptor... interceptors)
See Also
Binder#bindInterceptor
bindListenerback to summary
protected void bindListener(Matcher<? super TypeLiteral<?>> typeMatcher, TypeListener listener)
Since
2.0
See Also
Binder#bindListener(com.google.inject.matcher.Matcher, com.google.inject.spi.TypeListener)
bindListenerback to summary
protected void bindListener(Matcher<? super Binding<?>> bindingMatcher, ProvisionListener... listener)
Since
4.0
See Also
Binder#bindListener(Matcher, ProvisionListener...)
bindScopeback to summary
protected void bindScope(Class<? extends Annotation> scopeAnnotation, Scope scope)
See Also
Binder#bindScope(Class, Scope)
configureback to summary
public final synchronized void configure(Binder builder)

Implements com.google.inject.Module.configure.

Doc from com.google.inject.Module.configure.

Contributes bindings and other configurations for this module to binder.

Do not invoke this method directly to install submodules. Instead use Binder#install(Module), which ensures that provider methods are discovered.

Annotations
@Override
configureback to summary
protected void configure()

Configures a Binder via the exposed methods.

convertToTypesback to summary
protected void convertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher, TypeConverter converter)
Since
2.0
See Also
Binder#convertToTypes
currentStageback to summary
protected Stage currentStage()
Since
2.0
See Also
Binder#currentStage()
getMembersInjectorback to summary
protected <T> MembersInjector<T> getMembersInjector(Class<T> type)
Since
2.0
See Also
Binder#getMembersInjector(Class)
getMembersInjectorback to summary
protected <T> MembersInjector<T> getMembersInjector(TypeLiteral<T> type)
Since
2.0
See Also
Binder#getMembersInjector(TypeLiteral)
getProviderback to summary
protected <T> Provider<T> getProvider(Key<T> key)
Since
2.0
See Also
Binder#getProvider(Key)
getProviderback to summary
protected <T> Provider<T> getProvider(Class<T> type)
Since
2.0
See Also
Binder#getProvider(Class)
installback to summary
protected void install(Module module)
See Also
Binder#install(Module)
requestInjectionback to summary
protected void requestInjection(Object instance)
Since
2.0
See Also
Binder#requestInjection(Object)
requestInjectionback to summary
protected <T> void requestInjection(TypeLiteral<T> type, T instance)
Since
6.0
See Also
Binder#requestInjection(TypeLiteral, Object)
requestStaticInjectionback to summary
protected void requestStaticInjection(Class<?>... types)
See Also
Binder#requestStaticInjection(Class[])
requireBindingback to summary
protected void requireBinding(Key<?> key)

Adds a dependency from this module to 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.

Since
2.0
requireBindingback to summary
protected void requireBinding(Class<?> type)

Adds a dependency from this module to 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.

Since
2.0