How do I inject the dependencies I have created in Play application. I also do not understand looking at the examples how they are injected without defining any binding.
Can anyone explain with reference to this example. How is object of VocabularyService injected?
This question is more about dependency injection than it is about the Play Framework.
The reason that you don't have to define an explicit binding for the VocabularyService
is that Guice can find it for you:
When a dependency is requested but not found it attempts to create a just-in-time binding.
from: Guice Bindings
On the documentation of just-in-time bindings you can see that the option for creating a just-in-time binding are Eligible Constructors
, @ImplementedBy
and @ProvidedBy
.
In our case, the class VocabularyService
has a default non-private, no-arguments constructor.