Package com.google.inject
Class AbstractModule
java.lang.Object
com.google.inject.AbstractModule
- All Implemented Interfaces:
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 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:
- crazybob@google.com (Bob Lee)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidprotected voidprotected <T> LinkedBindingBuilder<T> protected <T> AnnotatedBindingBuilder<T> bind(TypeLiteral<T> typeLiteral) protected <T> AnnotatedBindingBuilder<T> SeeBinder.bind(Class).protected AnnotatedConstantBindingBuilderprotected Binderbinder()Gets direct access to the underlyingBinder.protected voidbindInterceptor(Matcher<? super Class<?>> classMatcher, Matcher<? super Method> methodMatcher, org.aopalliance.intercept.MethodInterceptor... interceptors) protected voidbindListener(Matcher<? super Binding<?>> bindingMatcher, ProvisionListener... listener) protected voidbindListener(Matcher<? super TypeLiteral<?>> typeMatcher, TypeListener listener) protected voidbindScope(Class<? extends Annotation> scopeAnnotation, Scope scope) protected voidConfigures aBindervia the exposed methods.final voidContributes bindings and other configurations for this module tobinder.protected voidconvertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher, TypeConverter converter) protected Stageprotected <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 voidprotected <T> voidrequestInjection(TypeLiteral<T> type, T instance) protected voidrequestInjection(Object instance) protected voidrequestStaticInjection(Class<?>... types) protected voidrequireBinding(Key<?> key) Adds a dependency from this module tokey.protected voidrequireBinding(Class<?> type) Adds a dependency from this module totype.
-
Constructor Details
-
AbstractModule
public AbstractModule()
-
-
Method Details
-
configure
Description copied from interface:ModuleContributes 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 methodsare discovered. -
configure
protected void configure()Configures aBindervia the exposed methods. -
binder
Gets direct access to the underlyingBinder. -
bindScope
- See Also:
-
bind
- See Also:
-
bind
-
bind
SeeBinder.bind(Class). -
bindConstant
- See Also:
-
install
- See Also:
-
addError
- See Also:
-
addError
- See Also:
-
addError
- Since:
- 2.0
- See Also:
-
requestInjection
- Since:
- 2.0
- See Also:
-
requestInjection
- Since:
- 6.0
- See Also:
-
requestStaticInjection
- See Also:
-
bindInterceptor
protected void bindInterceptor(Matcher<? super Class<?>> classMatcher, Matcher<? super Method> methodMatcher, org.aopalliance.intercept.MethodInterceptor... interceptors) - See Also:
-
requireBinding
Adds a dependency from this module tokey. When the injector is created, Guice will report an error ifkeycannot be injected. Note that this requirement may be satisfied by implicit binding, such as a public no-arguments constructor.- Since:
- 2.0
-
requireBinding
Adds a dependency from this module totype. When the injector is created, Guice will report an error iftypecannot be injected. Note that this requirement may be satisfied by implicit binding, such as a public no-arguments constructor.- Since:
- 2.0
-
getProvider
- Since:
- 2.0
- See Also:
-
getProvider
- Since:
- 2.0
- See Also:
-
convertToTypes
- Since:
- 2.0
- See Also:
-
currentStage
- Since:
- 2.0
- See Also:
-
getMembersInjector
- Since:
- 2.0
- See Also:
-
getMembersInjector
- Since:
- 2.0
- See Also:
-
bindListener
- Since:
- 2.0
- See Also:
-
bindListener
protected void bindListener(Matcher<? super Binding<?>> bindingMatcher, ProvisionListener... listener) - Since:
- 4.0
- See Also:
-