O'Reilly logo

Learning Google Guice by Hussain Pithawala

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Configuring a module to write bindings

There are two ways by which we can configure the bindings:

  • Firstly by extending the abstract class com.google.inject.AbstractModule
    @Override
    protected void configure() {
    }
  • Secondly by implementing the interface com.google.inject.Module
    @Override
    public void configure(Binder binder) {
    }

Tip

It is suggested that modules must be extended using AbstractModule. It provides a more readable configuration and also avoids repletion of invoking methods on binder.

We have simply followed one module per class strategy. Also, for the sake of illustration, we have developed all the modules as the method local classes in the main() method of Client.class. In the next chapter we will discuss more about structuring modules in a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required