# Dagger 2 Tutorial For Android: Advanced | raywenderlich.com

**URL:** <https://forums.kodeco.com/t/dagger-2-tutorial-for-android-advanced-raywenderlich-com/98631>\
**Category:** 🎓 Courses & Articles\
**Created:** [February 18, 2020, 8:31am UTC](https://forums.kodeco.com/t/dagger-2-tutorial-for-android-advanced-raywenderlich-com/98631 "2020-02-18T08:31:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![massimocarli](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/massimocarli/32/108300_2.png) [@massimocarli](https://forums.kodeco.com/u/massimocarli)\
**Post date:** [February 18, 2020, 8:31am UTC](https://forums.kodeco.com/t/dagger-2-tutorial-for-android-advanced-raywenderlich-com/98631/1 "2020-02-18T08:31:53Z")

</div>

Dagger is arguably the most used Dependency Injection, or DI, framework for Android. Many Android projects use Dagger to simplify building and providing dependencies across the app. It gives you the ability to create specific scopes, modules, and components, where each forms a piece of a puzzle: The dependency graph. Unfortunately, Dagger can’t solve every […]

* * *
This is a companion discussion topic for the original entry at [https://www.raywenderlich.com/6583167-dagger-2-tutorial-for-android-advanced](https://www.raywenderlich.com/6583167-dagger-2-tutorial-for-android-advanced)

---

<div class="post-metadata">

**Author:** ![tartarjr](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/tartarjr/32/102075_2.png) [@tartarjr](https://forums.kodeco.com/u/tartarjr)\
**Post date:** [February 27, 2020, 3:31pm UTC](https://forums.kodeco.com/t/dagger-2-tutorial-for-android-advanced-raywenderlich-com/98631/2 "2020-02-27T15:31:07Z")

</div>

It is not really a good idea to make your fragment dependencies singleton and make them live for the entire lifetime of the app. Imagine you have a big application with a lot of dependencies flying around. You would have memory problems. I would rather be creating a fragment component with a custom scope to inject fragments. AppComponent should only provide real singletons such as network client, database, etc.

---

<div class="post-metadata">

**Author:** ![tartarjr](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/tartarjr/32/102075_2.png) [@tartarjr](https://forums.kodeco.com/u/tartarjr)\
**Post date:** [February 27, 2020, 3:37pm UTC](https://forums.kodeco.com/t/dagger-2-tutorial-for-android-advanced-raywenderlich-com/98631/3 "2020-02-27T15:37:38Z")

</div>

Also, why would you provide a repository via component here? `.appModule(AppModule(MemoryNewsRepository()))`  
The example above can be very misleading.

You can simply use constructor injection and provide it to the dependency tree, you don’t even need a module for the classes that you own. Using modules with dependencies is not a good Dagger 2 practice. Keep the modules dumb and if you are using provide methods make them static(In Kotlin you do not even need` @JvmStatic` anymore just use the Kotlin `object`) or use abstract modules with `@Binds` anytime possible.By doing this you ll make Dagger implement less classes and improve the performance. If you need to add something to the dependency tree during runtime (such as `applicationContext`) `@BindsInstance` is enough.

---

<div class="post-metadata">

**Author:** ![tartarjr](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/tartarjr/32/102075_2.png) [@tartarjr](https://forums.kodeco.com/u/tartarjr)\
**Post date:** [February 27, 2020, 3:41pm UTC](https://forums.kodeco.com/t/dagger-2-tutorial-for-android-advanced-raywenderlich-com/98631/4 "2020-02-27T15:41:21Z")

</div>

I suggest you re-consider your article to avoid misunderstandings.

---

<div class="post-metadata">

**Author:** ![massimocarli](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/massimocarli/32/108300_2.png) [@massimocarli](https://forums.kodeco.com/u/massimocarli)\
**Post date:** [February 27, 2020, 11:16pm UTC](https://forums.kodeco.com/t/dagger-2-tutorial-for-android-advanced-raywenderlich-com/98631/5 "2020-02-27T23:16:14Z")

</div>

Hi @tartarjr  
Thank you very much for your messages. The goal of the tutorial is not to describe a single solution to copy and paste but to understand what’s behind Dagger in order to consider the pros and cons of all the possible options. In your messages, you also provided 4 different solutions, all valid, for the problem described in the tutorial.  
What you said about the Fragment is right but it’s part of the process which allow me to describe the problem and the possible solution which will be part of the second part of tutorial, we’re going to publish very soon.

Thanks  
Max

---

<div class="post-metadata">

**Author:** ![tartarjr](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/tartarjr/32/102075_2.png) [@tartarjr](https://forums.kodeco.com/u/tartarjr)\
**Post date:** [February 28, 2020, 8:20am UTC](https://forums.kodeco.com/t/dagger-2-tutorial-for-android-advanced-raywenderlich-com/98631/6 "2020-02-28T08:20:06Z")

</div>

Hi Max! Thank you for your reply. I see, looking forward to read the second part.

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [April 8, 2021, 8:53am UTC](https://forums.kodeco.com/t/dagger-2-tutorial-for-android-advanced-raywenderlich-com/98631/7 "2021-04-08T08:53:29Z")

</div>

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [April 8, 2021, 8:53am UTC](https://forums.kodeco.com/t/dagger-2-tutorial-for-android-advanced-raywenderlich-com/98631/8 "2021-04-08T08:53:32Z")

</div>


