-
Notifications
You must be signed in to change notification settings - Fork 2k
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Update documentation for dagger-android in order to show how to use custom scopes #1352
Comments
I created sample app how to use custom scopes with dagger-android https://github.com/roshakorost/Dagger-Android-Cookbook/tree/master/customscopes The overall aproach is very simple, basically you should detect what component to use in your application. I am going to create severall small projects with varios injection stuff, related to dagger android. Please, create issues in case you want something to see. |
Is it possible to have two fragments with different scopes in same activity(which is in same scope as one of the fragments). I asked this question on stackoverflow(https://stackoverflow.com/questions/53761310/dagger-2-fragments-with-different-scope) |
@roshakorost Thanks a lot for sharing the example :)
instead of Subcomponent? |
I'm going to close this because dagger-android isn't really being developed now that Hilt is released. While we are still keeping dagger-android maintained, I think this topic is probably complex enough that it would be a fair amount of documentation to write that unfortunately would be a fairly large amount of work. |
In Android world most apps have authorization. Dagger helps with that a lot, as it allows to create custom
subcopoment
s/scope
s for authorized user.The following setup is very usedfull for me:
ApplicationScope
andAplicationComponent
- the root compontent with some basic AndroidDependecies.NonAuthorizedScope
and corresponding component, which is used accross login, sign up and screens that doesn't need authorization.AuthorizedScope
and its compoent, which is created after login and is kept untill logout. It is very helpfull for storing access token and some user preferences.For long time I thought that such setup is not possible to achieve by dagger-android. The documentation suggests that you should have application component and subcomponents per activity and per fragment.
However, I just found ssue #1267 which has suggestions how to organize simmialr component hirereachy and how to use it with dagger-android.
It would be wonderfull to update the documentation with such example. Also example app will be helpfull a lot.
The text was updated successfully, but these errors were encountered: