https://kotlinlang.org logo
#android
Title
# android
l

Lilly

03/27/2019, 8:45 PM
ok nice. I have a component that should die with my fragment. Should I instantiate this component in application as singleton and provide it in my fragment or should I instantiate it in fragment everytime it is started? @jw oh the question isn't Kotlin specific at all ^^ but I would appreciate some help
t

tseisel

03/27/2019, 8:51 PM
Do you use
dagger-android
?
l

Lilly

03/27/2019, 9:01 PM
no I often read in tutorials that one can get along without it and that its not necessary but I don't know why yet. My journey just started ^^
t

tseisel

03/27/2019, 9:27 PM
Just like RxJava, Dagger is a marvellous tool that can make your life a lot easier when correctly used, but they are also known for their steep learning curve. As a starting point, I suggest you to have a look at this sample project (this uses dagger-android) : https://github.com/googlesamples/android-architecture/tree/todo-mvp-dagger
Also, I you really want to tame the beast, I recommend reading this awesome series of blog posts : https://proandroiddev.com/dagger-2-android-defeat-the-dahaka-b1c542233efc
l

Lilly

03/27/2019, 9:49 PM
I will check this out and come back 🙂
g

ghedeon

03/27/2019, 10:42 PM
dagger-android
will help with injection into fragment, not with scoping. And seems like fragment scope is the requirement.
a

arekolek

03/28/2019, 7:53 AM
I hope you’re not saying that you can’t scope the component when using
dagger-android
, because you can
l

Lilly

03/28/2019, 11:37 AM
I read the whole series and also I had a further look into the dagger documentation and indeed some questions get answered. But I still don't understand why not to use
dagger-android
. I found 2 blog posts that do not recommend the usage and also Jake Wharton stated about that "It's only useful in highly modularized scenarios. There's no point in using it when your activities and fragments live in the same module as your application." The arguments of the blog post authors not to use
dagger-android
are: 1. You can scope with viewModel so you don't need additional subcomponents for scoping as far as you let your dependencies unscoped and let them die with the viewModel... 2. The complexity of the setup/configuration especially for beginners Btw... I'm using MVVM with AAC So whats wrong with
dagger-android
? Is there any additional overhead when using it or
subcomponents
in general? What do you think guys?
2 Views