-
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
Dagger Android with multiple levels of (Sub)Components #1087
Comments
I don't use Dagger Android and I have no idea if this solution will meet your needs, but I'll share a semi-similar setup I use in my project and you can determine if it's useful.
I have an intermediate XxxxxxxxSharedComponent that has ApplicationComponent as a dependency and only contains items that need to be shared across my other subcomponents and exposes the builders for them. Previously I used to have XxxxxxxxSharedComponent be a sort of parent component that had similar responsibilities as the subcomponents + more, but I found that this lead to the excess of @ParentXxxxxxXxxx and @ChildXxxxxxXxxxx like qualifiers. Now I leverage the encapsulation of the subcomponents and only provide instances in XxxxxxxxSharedComponent that I truly mean to share. I hope that's somewhat helpful and I'd be happy to listen to others' thoughts and/or ideas for successful setups. |
@jhowens89 that's definitely the type of approach I was expecting from Dagger Android. That's what I had in mind if I had to implement a custom solution. However, instead of SharedLogic, I'd group them by features: e.g. registration, login, feature1, feature2... Thanks for commenting |
Hi @ronshapiro Do you know if this is possible with the current version or if you have some plans to add support to this in future versions of Dagger Android? Thank you. |
To me, this gtihub repo looks like it implements what's described in this issue. |
Here's a snippet I recently wrote up about this: #1267 |
I wonder if it's possible to have different levels of Components or Subcomponents using Dagger Android.
The idea is to abstract common Subcomponents data out to a common Component or Subcomponent.
Something like:
ApplicationComponent -> CommonLoginSubcomponent -> LoginActivitySubcomponent
CommonLoginSubcomponent could be either a Subcomponent or a Component.
I tried implementing something like that and Dagger couldn't generate the Subcomponent Builder of
LoginActivitySubcomponent
from theCommonLoginSubcomponent
that should've been used in the generated code ofApplicationComponent
to inject theLoginActivity
with theLoginActivitySubcomponent
.I assume this is not possible to do with Dagger Android right now. It seems like it only allows a level in the subcomponent hierarchy and doesn't allow having other Components including
ApplicationComponent
.Is there any plans on implementing this solution in the future?
Ideally, an intermediate Component or Subcomponent would also be able to support the
@IntoMap
bindings between Activities and Subcomponent Builders.The text was updated successfully, but these errors were encountered: