Class AbstractModule

  • All Implemented Interfaces:
    Module
    Direct Known Subclasses:
    BoundFieldModule.WithPermits, GraphvizModule, PersistModule, ServletModule

    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 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);
       }
     }