Package org.elasticsearch.common.inject
Class AbstractModule
java.lang.Object
org.elasticsearch.common.inject.AbstractModule
- All Implemented Interfaces:
Module
- Direct Known Subclasses:
ActionModule,ClusterModule,GatewayModule,IndicesModule
public abstract class AbstractModule extends java.lang.Object implements Module
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);
}
}
-
Constructor Summary
Constructors Constructor Description AbstractModule() -
Method Summary
Modifier and Type Method Description protected voidaddError(java.lang.String message, java.lang.Object... arguments)protected voidaddError(java.lang.Throwable t)protected voidaddError(Message message)protected <T> AnnotatedBindingBuilder<T>bind(java.lang.Class<T> clazz)protected <T> LinkedBindingBuilder<T>bind(Key<T> key)protected <T> AnnotatedBindingBuilder<T>bind(TypeLiteral<T> typeLiteral)protected AnnotatedConstantBindingBuilderbindConstant()protected Binderbinder()Gets direct access to the underlyingBinder.protected voidbindListener(Matcher<? super TypeLiteral<?>> typeMatcher, TypeListener listener)protected voidbindScope(java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation, Scope scope)protected abstract voidconfigure()Configures aBindervia the exposed methods.voidconfigure(Binder builder)Contributes bindings and other configurations for this module tobinder.protected voidconvertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher, TypeConverter converter)protected StagecurrentStage()protected <T> MembersInjector<T>getMembersInjector(java.lang.Class<T> type)protected <T> MembersInjector<T>getMembersInjector(TypeLiteral<T> type)protected <T> Provider<T>getProvider(java.lang.Class<T> type)protected <T> Provider<T>getProvider(Key<T> key)protected voidinstall(Module module)protected voidrequestInjection(java.lang.Object instance)protected voidrequestStaticInjection(java.lang.Class<?>... types)protected voidrequireBinding(java.lang.Class<?> type)Adds a dependency from this module totype.protected voidrequireBinding(Key<?> key)Adds a dependency from this module tokey.
-
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 abstract void configure()Configures aBindervia the exposed methods. -
binder
Gets direct access to the underlyingBinder. -
bindScope
protected void bindScope(java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation, Scope scope)- See Also:
Binder.bindScope(Class, Scope)
-
bind
- See Also:
Binder.bind(Key)
-
bind
- See Also:
Binder.bind(TypeLiteral)
-
bind
- See Also:
Binder.bind(Class)
-
bindConstant
- See Also:
Binder.bindConstant()
-
install
- See Also:
Binder.install(Module)
-
addError
protected void addError(java.lang.String message, java.lang.Object... arguments)- See Also:
Binder.addError(String, Object[])
-
addError
protected void addError(java.lang.Throwable t)- See Also:
Binder.addError(Throwable)
-
addError
- Since:
- 2.0
- See Also:
Binder.addError(Message)
-
requestInjection
protected void requestInjection(java.lang.Object instance)- Since:
- 2.0
- See Also:
Binder.requestInjection(Object)
-
requestStaticInjection
protected void requestStaticInjection(java.lang.Class<?>... types)- See Also:
Binder.requestStaticInjection(Class[])
-
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
protected void requireBinding(java.lang.Class<?> type)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:
Binder.getProvider(Key)
-
getProvider
- Since:
- 2.0
- See Also:
Binder.getProvider(Class)
-
convertToTypes
protected void convertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher, TypeConverter converter) -
currentStage
- Since:
- 2.0
- See Also:
Binder.currentStage()
-
getMembersInjector
- Since:
- 2.0
- See Also:
Binder.getMembersInjector(Class)
-
getMembersInjector
- Since:
- 2.0
- See Also:
Binder.getMembersInjector(TypeLiteral)
-
bindListener
-