Instance bindings

Instance bindings help to bind a type to a particular instance of that typeThis is normally helpful only for objects that don't have dependencies in their possession; for example, value objects:

Public class SearchModule extends AbstractModule{    @Override    protected void configure() {        bind(SearchParameters.class).toInstance(new SearchParameters());    }}

Avoid utilizing .toInstance with objects that are complicated to make, since it can slow down application start-up. You can utilize the @Provides technique.

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.