Package com.google.inject
Class AbstractModule
- java.lang.Object
-
- com.google.inject.AbstractModule
-
- All Implemented Interfaces:
Module
public abstract class AbstractModule extends Object implements Module
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 inBinder
. 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 Summary
Constructors Constructor Description AbstractModule()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addError(Message message)
protected void
addError(String message, Object... arguments)
protected void
addError(Throwable t)
protected <T> LinkedBindingBuilder<T>
bind(Key<T> key)
protected <T> AnnotatedBindingBuilder<T>
bind(TypeLiteral<T> typeLiteral)
protected <T> AnnotatedBindingBuilder<T>
bind(Class<T> clazz)
SeeBinder.bind(Class)
.protected AnnotatedConstantBindingBuilder
bindConstant()
protected Binder
binder()
Gets direct access to the underlyingBinder
.protected void
bindInterceptor(Matcher<? super Class<?>> classMatcher, Matcher<? super Method> methodMatcher, MethodInterceptor... interceptors)
protected void
bindListener(Matcher<? super Binding<?>> bindingMatcher, ProvisionListener... listener)
protected void
bindListener(Matcher<? super TypeLiteral<?>> typeMatcher, TypeListener listener)
protected void
bindScope(Class<? extends Annotation> scopeAnnotation, Scope scope)
protected void
configure()
Configures aBinder
via the exposed methods.void
configure(Binder builder)
Contributes bindings and other configurations for this module tobinder
.protected void
convertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher, TypeConverter converter)
protected Stage
currentStage()
protected <T> MembersInjector<T>
getMembersInjector(TypeLiteral<T> type)
protected <T> MembersInjector<T>
getMembersInjector(Class<T> type)
protected <T> Provider<T>
getProvider(Key<T> key)
protected <T> Provider<T>
getProvider(Class<T> type)
protected void
install(Module module)
protected <T> void
requestInjection(TypeLiteral<T> type, T instance)
protected void
requestInjection(Object instance)
protected void
requestStaticInjection(Class<?>... types)
protected void
requireBinding(Key<?> key)
Adds a dependency from this module tokey
.protected void
requireBinding(Class<?> type)
Adds a dependency from this module totype
.
-
-
-
Method Detail
-
configure
public final void configure(Binder builder)
Description copied from interface:Module
Contributes bindings and other configurations for this module tobinder
.Do not invoke this method directly to install submodules. Instead use
Binder.install(Module)
, which ensures thatprovider methods
are discovered.
-
configure
protected void configure()
Configures aBinder
via the exposed methods.
-
binder
protected Binder binder()
Gets direct access to the underlyingBinder
.
-
bindScope
protected void bindScope(Class<? extends Annotation> scopeAnnotation, Scope scope)
- See Also:
Binder.bindScope(Class, Scope)
-
bind
protected <T> LinkedBindingBuilder<T> bind(Key<T> key)
- See Also:
Binder.bind(Key)
-
bind
protected <T> AnnotatedBindingBuilder<T> bind(TypeLiteral<T> typeLiteral)
-
bind
protected <T> AnnotatedBindingBuilder<T> bind(Class<T> clazz)
SeeBinder.bind(Class)
.
-
bindConstant
protected AnnotatedConstantBindingBuilder bindConstant()
- See Also:
Binder.bindConstant()
-
install
protected void install(Module module)
- See Also:
Binder.install(Module)
-
addError
protected void addError(String message, Object... arguments)
- See Also:
Binder.addError(String, Object[])
-
addError
protected void addError(Throwable t)
- See Also:
Binder.addError(Throwable)
-
addError
protected void addError(Message message)
- Since:
- 2.0
- See Also:
Binder.addError(Message)
-
requestInjection
protected void requestInjection(Object instance)
- Since:
- 2.0
- See Also:
Binder.requestInjection(Object)
-
requestInjection
protected <T> void requestInjection(TypeLiteral<T> type, T instance)
- Since:
- 6.0
- See Also:
Binder.requestInjection(TypeLiteral, Object)
-
requestStaticInjection
protected void requestStaticInjection(Class<?>... types)
- See Also:
Binder.requestStaticInjection(Class[])
-
bindInterceptor
protected void bindInterceptor(Matcher<? super Class<?>> classMatcher, Matcher<? super Method> methodMatcher, MethodInterceptor... interceptors)
-
requireBinding
protected void requireBinding(Key<?> key)
Adds a dependency from this module tokey
. When the injector is created, Guice will report an error ifkey
cannot be injected. Note that this requirement may be satisfied by implicit binding, such as a public no-arguments constructor.- Since:
- 2.0
-
requireBinding
protected void requireBinding(Class<?> type)
Adds a dependency from this module totype
. When the injector is created, Guice will report an error iftype
cannot be injected. Note that this requirement may be satisfied by implicit binding, such as a public no-arguments constructor.- Since:
- 2.0
-
getProvider
protected <T> Provider<T> getProvider(Key<T> key)
- Since:
- 2.0
- See Also:
Binder.getProvider(Key)
-
getProvider
protected <T> Provider<T> getProvider(Class<T> type)
- Since:
- 2.0
- See Also:
Binder.getProvider(Class)
-
convertToTypes
protected void convertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher, TypeConverter converter)
-
currentStage
protected Stage currentStage()
- Since:
- 2.0
- See Also:
Binder.currentStage()
-
getMembersInjector
protected <T> MembersInjector<T> getMembersInjector(Class<T> type)
- Since:
- 2.0
- See Also:
Binder.getMembersInjector(Class)
-
getMembersInjector
protected <T> MembersInjector<T> getMembersInjector(TypeLiteral<T> type)
- Since:
- 2.0
- See Also:
Binder.getMembersInjector(TypeLiteral)
-
bindListener
protected void bindListener(Matcher<? super TypeLiteral<?>> typeMatcher, TypeListener listener)
-
bindListener
protected void bindListener(Matcher<? super Binding<?>> bindingMatcher, ProvisionListener... listener)
- Since:
- 4.0
- See Also:
Binder.bindListener(Matcher, ProvisionListener...)
-
-