April 2018
Intermediate to advanced
246 pages
6h 11m
English
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.