https://kotlinlang.org logo
#dagger
Title
# dagger
k

Kavin

06/18/2019, 6:07 AM
This is what my code looks like
g

gildor

06/18/2019, 6:08 AM
And where do you inject interactorLookup property?
also not really sure why do you use property injection instead of constructor injection
k

Kavin

06/18/2019, 6:11 AM
I get error at
lateinit var interactorLookup
. I’m aware I’m doing the property injection for now, but I’m not sure what’s wrong here! (Atleast I didn’t get the missing part yet)
g

gildor

06/18/2019, 6:38 AM
But you have this property, but I don’t see where do you inject it
it should be some
inject(this)
in LookupViewPresenter
I see in your snippet inject fro Activity, but not for LookupViewPresenter
Property will not be injected automatically, only explicitly
and I still don’t understand why you cannot use constructor injection:
Copy code
class LookupViewPresenter @Inject constructor(
   mView: LookupViewContract.View, 
   val interactorLookup: LookupInteractorImpl
)
k

Kavin

06/18/2019, 9:48 AM
But let’s say I have multiple Interactors in my Presenter. Will it be nice to use constructor injection?
g

gildor

06/18/2019, 10:17 AM
Use constructor injections is always nice, there is no cases when usage of field/method injection would be better than use constructor
if you have multiple Interactors of the same type just use qualifiers to distinguish between them
k

Kavin

06/21/2019, 6:10 AM
Sorry for the later reply, I was held up with something else. So I have 6 different types of Interactors in my presenter! You suggest me to do constructor injection for all?
g

gildor

06/21/2019, 9:46 AM
Hmm, not 100% sure what you mean by “do constructor injection for all”
My point that if you can use constuctor injection (aka this class is not instantiated by Android Framework) you should use constructor injection and keep field injection only for cases when you have no another choice (like Android Framework components)
👍 1
k

Kavin

06/21/2019, 9:47 AM
Yeah got it. I have done it via constructor injection
Thanks for your help.. 👍
2 Views