Binder

This interface mainly includes information associated with bindings. A binding normally consists of a mapping between an interface and a concrete implementation. For example, if we consider an implementation of the module interface for creating custom module, then the reference to the interface NotificationService is bound to the SMSService implementation.

When coding, notice that the objects for both the interface and implementation classes are passed to the bind() and then to() methods:

binder.bind(NotificationService.class).to(SMSService.class);

The second way is to tie an interface directly to its instance by writing the following code:

binder.bind(NotificationService.class).to(new SMSService());

Get Java 9 Dependency Injection now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.