Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why doesn't the current ApplicationModule have provideNavigator()? #108

Open
ehdtkqorl123 opened this issue Feb 7, 2016 · 2 comments
Open

Comments

@ehdtkqorl123
Copy link

In your post here(http://fernandocejas.com/2015/04/11/tasting-dagger-2-on-android/),
I see the following method in ApplicationModule class but the actual github code doesn't have this method. But what is weird is, this runs even without it.
Can you explain how so? Thanks!

@provides @singleton Navigator provideNavigator() {
return new Navigator();
}

@vtuan10
Copy link

vtuan10 commented Feb 7, 2016

It is the same reason why presenters are not provided.
Most of the time you use injection by constructor to satisfy the dependencies in dagger 2.
Here we used:

@Inject
public Navigator() {}

to tell Dagger to use the constructor to create instances of Navigator.
You only need provide-methods, if dagger doesn't know how to construct the object. That's when you use third-party classes or you use an interface and dagger doesn't know which implementation it should use.
The explanation in the article is wrong. So only use modules for interfaces, third-party classes and objects which need to be configured. Less code, less bugs.

@android10
Copy link
Owner

@ehdtkqorl123 the code is being refactor and it is very hard to keep everything up to date, specially because of the lack of time. That is why we are trying to have discussions here and find the best way to address the different problems we come across with.

@vtuan10 thanks for the explanation 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants