Is there a way to bind a dependency twice? Once in SingletonComponent, once in ActivityComponent? In my use case I have two instances of a dependency: once in an Activity and once in a Service. The dependency itself depends on a
Context
, so I want to use the Activity context where possible.
I suppose I could accomplish this binding with annotations, but I was wondering if there was another way.
➕ 1
f
FunkyMuse
10/27/2021, 5:54 AM
You can use assisted inject for this and have the context as assisted dependency
w
wasyl
10/27/2021, 7:11 AM
IMO appropriate way to provide the same dependency twice in different scopes is to use qualifiers. Otherwise how would you decide which one to inject, if both are available?
c
Chris Fillmore
10/27/2021, 2:21 PM
Thanks for responding.
In the end, because I needed one in an Activity and one in a Service, I put one in ActivityComponent and the other in ServiceComponent, so there was no collision.