Untargeted bindings

Binding that can be created without target is known as an untargeted bindings. These are really signs to the injector around a type, so that the dependencies are arranged eagerly. In untargeted binding, we do not require the to clause:

bind(SampleConcreteClass.class).in(Singleton.class);
//Another way to define untargeted bindingbind(String.class).toInstance("./alerts/");

In this statement, the injector would prepare an instance of the String class eagerly with a value of  ./alerts/. When dependency injection requires it to inject the instance of String, it will inject this specific instance. This binding is useful when defining concrete classes and types annotated by @ImplementedBy or @ProvidedBy

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.