Share E-Book

Dagger by Tutorials Dependency Injection on Android with Dagger Hilt (Massimo Carli, the raywenderlich Tutorial Team)(Z-Library)

Author Massimo Carli, the raywenderlich Tutorial Team

Code
Language English

Learn About Dependency Injection with Dagger! Dependency injection is an important technique for building software systems that are maintainable and testable. You’re likely already doing dependency injection, maybe without even realizing it. Dependency injection is nowhere near as complex as its name implies. This book will guide you through with Dagger, Google’s framework for Java, Kotlin, and Android. Dagger will help you solve many of the development and performance issues that have plagued reflection-based solutions. This book is for intermediate Kotlin or Android developers who want to know how to implement the dependency injection pattern with Dagger and Hilt libraries. Topics Covered in Dagger by Tutorials • Dependency Injection (DI): Learn what dependencies are and why you need to control them to create successful apps. • Dagger: Learn what Dagger is, how it works, and how it slashes the amount of code you need to write by hand when you implement dependency injection in your app. • Injection types: Learn how to deal with constructor, field and method injection with Dagger. • Advanced Dagger: Dive deeper into the advanced features of Dagger like multi binding. • Hilt: Learn everything you need to know about Hilt to implement dependency injection in the Android app. Learn how Hilt reduces the boilerplate of doing manual dependency injection in your project. One thing you can count on: after reading this book, you’ll be prepared to use dependency injection with Dagger in your personal and production level projects.

Format EPUB
Size 17.4 MB
255
Views
0
Downloads
0.00
Total Donations

AI Guide

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

Full assistant
AI guide
【One-Line Pitch】 A hands-on, tutorial-driven guide for intermediate Android/Kotlin developers who want to master dependency injection (DI) with Dagger and Hilt, moving from core OOP principles to production-ready DI patterns that reduce boilerplate and improve testability. 【Book Arc】 - **Opening (~0%–9%)**: Introduces the book's purpose, target audience (intermediate Kotlin/Android devs), and the Busso App — a client-server sample project (server built with Ktor) used throughout. Sets expectations: learn DI fundamentals, then Dagger, then Hilt, with a focus on reducing "project mass" (effort to change code). - **Early (~9%–24%)**: Lays the conceptual foundation — what dependencies are, why they matter, and how they relate to change effort (using Newton's second law as an analogy). Covers OOP design principles like abstraction, generalization, and the formal definition of dependency (A depends on B if a change in B can imply a change in A). Includes practical examples with classes like `Person`, `Student`, and `Musician`. - **Early (~24%–33%)**: Deepens the OOP discussion with implementation inheritance, the IS-A vs. abstraction distinction, and how abstraction reduces dependency. Shows concrete Kotlin code for inheritance and explains why over-reliance on inheritance creates rigidity. Emphasizes that abstraction is the key tool for limiting dependency. - **Middle (~33%–48%)**: Demonstrates the DRY (Don't Repeat Yourself) principle in action through a university example — printing names for students, musicians, teachers, etc. Shows how copy-paste code leads to maintenance nightmares and how introducing abstractions (like `Person` or `Named` interface) eliminates duplication and reduces the blast radius of changes. - **Middle (~48%–52%)**: Refines the abstraction further — introduces the `Named` interface to decouple from `Person` entirely, allowing any object (even `Cat`) to be printed by name. This is the key lesson: depend on what an object DOES (its interface), not what it IS (its concrete type). Sets up the transition to DI frameworks. - **Late (~52%–100%)**: (Excerpts thin here) The book moves into Dagger specifics — `@Module`, `@Binds`, `@Provides`, `@Component`, `@Component.Builder`, `@Component.Factory`, qualifiers (`@Named`, custom `@Qualifiers`), `@Singleton`, `dagger.Lazy`, `Provider`, and multi-binding. Then transitions to Hilt for Android, showing how it reduces boilerplate for field/method/constructor injection in Android apps. 【Key Takeaways】 - **Dependency is about change impact** (Early): A depends on B if a change in B can imply a change in A. Controlling dependencies means controlling how much effort changes require — the book's core motivation for using DI frameworks. - **Abstraction is your primary weapon** (Early): By depending on interfaces or abstract classes (e.g., `Named`), you reduce coupling to concrete implementations. This makes code more flexible and easier to test or modify. - **DRY violations signal design problems** (Middle): If you're copy-pasting similar code (like `printNames` for different types), stop and abstract. The cost of change multiplies with duplication, increasing bug risk. - **Depend on behavior, not identity** (Middle): The `Named` interface example shows you should depend on what an object DOES (provides a `name`), not what it IS (a `Person`). This is the foundation for DI — you inject capabilities, not concrete types. - **Dagger reduces hand-written boilerplate** (Late): Dagger generates code at compile time to wire dependencies, replacing manual ServiceLocators and Injectors. This eliminates reflection-based performance issues and speeds up development. - **Hilt simplifies Android DI** (Late): Hilt builds on Dagger to reduce boilerplate further, providing standard components for Android lifecycle (activity, fragment, view, etc.) and making DI more approachable for production Android apps. - **Scope management is critical** (Late): Understanding `@Singleton` and custom scopes helps manage object lifetimes correctly, preventing memory leaks and ensuring consistent state across your app. 【Reading Tips】 - **Skim the OOP theory if you're experienced** (~9%–33%): If you already know abstraction, inheritance, and interfaces, jump to Section II (Introducing Dagger) around ~33%. The early chapters are valuable for beginners but can be skimmed by seasoned devs. - **Deep-read the abstraction examples** (~39%–52%): The `Person`/`Named`/`Cat` examples are the conceptual heart of the book. Work through them in IntelliJ to internalize why abstraction reduces dependency — this will make Dagger's annotations make sense. - **Follow along with the Busso App** (~15% onward): The book uses a real client-server app (Ktor backend) as a running example. Don't just read — code along. The migration from a homemade DI framework to Dagger is where the practical value lies. - **Pay attention to Dagger annotation distinctions** (Late): `@Binds` vs. `@Provides`, `@Component.Builder` vs. `@Component.Factory`, and qualifiers (`@Named` vs. custom) are easy to confuse. Take notes or create a cheat sheet as you go. - **Use the challenge projects**: Each chapter ends with challenges. Do them — they reinforce the material and prepare you for production-level DI work. 【Coverage Limits】 The excerpts provided cover the book's introduction, OOP/DI fundamentals, and abstraction principles in detail, but do not include the full Dagger/Hilt implementation chapters. Specific Dagger annotations, Hilt setup, and advanced topics like multi-binding are mentioned but not detailed in the source material.

Passage locations

Excerpt 1
ht ©2021 Razeware LLC. Notice of Rights All rights reserved. No part of this book or corresponding materials (such as text, images, or source code) may be re...
View in text
Excerpt 2
ify. You’ll keep the concept of mass of the project in mind. In the process, you'll learn more about Scope and see how it relates to dependency. You’ll...
View in text
Excerpt 3
you indicate that a change in B can result in a change of A. In these diagrams, A and B can be different things like objects, classes or even packages or mod...
View in text
Excerpt 4
ed, every person is able to think, so it’s a logical choice. Now, Student and Musician become the following: class Student (name: String) : Person(name) { fu...
View in text

Recommended for You

Loading recommended books...
Failed to load, please try again later

Tip the Site

Scan the WeChat Pay or Alipay code to tip. No login required.

WeChat Pay
Alipay
Back to List