Open Johnny850807 opened 7 years ago
Those dependencies are automatically provided for you because they are constructor annotated.
For example provideThreadExecutor
requires a JobExecutor
. If you look at the class JobExecutor
you'll see that the class is annotated with a @Singleton
and the constructor is annotated with an @Inject
.
This way you don't have to provide it manually on your module.
Well, I think I almost understand, So the reason of why the author didn't have to write a provide method to Presenter and UseCase is that all of the them are written as a concrete subclass.
In order to keep the Dagger clean, we don't make a polymorphism to presenters or usecases, and this is unnecessary right?
That's right at least that's how I understand it!
For example JobExecutor
is an implementation of ThreadExecutor
. In the code JobExecutor
is used because you don't care about implementation. You let Dagger provide it for you.
But concerning Presenter
you actually need the implementation. Because a Presenter
is tightly coupled to a View
. An interface is used only for testing purpose to allow using mock and easily test each component separately.
Here exposing several dependencies such like those parameters jobExecutor, uiThread... But to my knowledge, there should be somewhere else provides the dependency here needs, otherwise error occurs. I can't find any module provides them, could someone please tell me why does this example work?