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 better way.
Developing modules as method local classes is not a suggested approach. It makes an application difficult to maintain. We have followed this approach for illustration purposes only. In the next chapter modules are developed as independent...