public abstract class

AbstractModule

extends Object
implements Module
java.lang.Object
   ↳ com.google.inject.AbstractModule
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

A support class for 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);
   }
 }
 

Summary

Public Constructors
AbstractModule()
Public Methods
synchronized final void configure(Binder builder)
Contributes bindings and other configurations for this module to binder.
Protected Methods
void addError(Message message)
void addError(String message, Object... arguments)
void addError(Throwable t)
<T> LinkedBindingBuilder<T> bind(Key<T> key)
<T> AnnotatedBindingBuilder<T> bind(TypeLiteral<T> typeLiteral)
<T> AnnotatedBindingBuilder<T> bind(Class<T> clazz)
AnnotatedConstantBindingBuilder bindConstant()
void bindInterceptor(Matcher<? super Class<?>> classMatcher, Matcher<? super Method> methodMatcher, MethodInterceptor... interceptors)
void bindListener(Matcher<? super TypeLiteral<?>> typeMatcher, TypeListener listener)
void bindScope(Class<? extends Annotation> scopeAnnotation, Scope scope)
Binder binder()
Gets direct access to the underlying Binder.
abstract void configure()
Configures a Binder via the exposed methods.
void convertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher, TypeConverter converter)
Stage currentStage()
<T> MembersInjector<T> getMembersInjector(TypeLiteral<T> type)
<T> MembersInjector<T> getMembersInjector(Class<T> type)
<T> Provider<T> getProvider(Key<T> key)
<T> Provider<T> getProvider(Class<T> type)
void install(Module module)
void requestInjection(Object instance)
void requestStaticInjection(Class...<?> types)
void requireBinding(Key<?> key)
Adds a dependency from this module to key.
void requireBinding(Class<?> type)
Adds a dependency from this module to type.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.google.inject.Module

Public Constructors

public AbstractModule ()

Public Methods

public final synchronized void configure (Binder builder)

Contributes bindings and other configurations for this module to binder.

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

Protected Methods

protected void addError (Message message)

protected void addError (String message, Object... arguments)

protected void addError (Throwable t)

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

See Also

protected AnnotatedBindingBuilder<T> bind (TypeLiteral<T> typeLiteral)

protected AnnotatedBindingBuilder<T> bind (Class<T> clazz)

See Also

protected AnnotatedConstantBindingBuilder bindConstant ()

See Also

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

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

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

protected Binder binder ()

Gets direct access to the underlying Binder.

protected abstract void configure ()

Configures a Binder via the exposed methods.

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

protected Stage currentStage ()

See Also

protected MembersInjector<T> getMembersInjector (TypeLiteral<T> type)

protected MembersInjector<T> getMembersInjector (Class<T> type)

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

See Also

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

protected void install (Module module)

See Also

protected void requestInjection (Object instance)

protected void requestStaticInjection (Class...<?> types)

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.

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.