Spring Ahead Sale — Save on Everything.All videos. All books. Now 50% off.

Build your mobile development skills and save! Stay ahead of the rest with an Ultimate book & video subscription. Starting at just $149/year as part of the Spring Ahead sale.

Home Android & Kotlin Tutorials

Announcing Dagger by Tutorials, First Edition!

We’re excited to announce that the first edition of our newest book, Dagger by Tutorials, is 100% complete and available today!

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, and this book will guide you through everything you need to know!

That’s why we’re excited to announce our newest book, Dagger by Tutorials, which is 100% complete and out today! Dagger by Tutorials will guide you through 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.

Read on to see what’s inside, and how to get your own copy of Dagger by Tutorials!

Who is Dagger by Tutorials For?

This book is designed for intermediate Kotlin or Android developers who want to know how to implement the dependency injection pattern with Dagger and Hilt libraries.

In this book, you’ll update an existing app named Busso to use dependency injection with Dagger and Hilt. The Busso app is a simple app that allows you to find bus stops near you and information about arrival times.

This book will serve you as a central point that holds all the information you need to dive deep into Dagger and Hilt, to apply it to your personal and production level projects.

This book has 21 chapters spread over five sections:

Section I: DI Fundamentals

In this section, you’ll 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.

Busso — the sample app you’ll use to master dependency injection!

You’ll learn how to deal with constructor, field and method injection with Dagger, how to simplify the implementation of @Module by using @Binds in cases when you have abstraction and its implementation, and how to use @Singleton to solve a very common problem.

  1. Design Principles: In this chapter, you’ll learn what is a dependency and how it impacts your code. You’ll also learn how you can write better code using abstractions.
  2. Meet the Busso App: In this chapter, you’ll get to know the Busso App, which you’ll work on and improve throughout this book. It’s a client-server app where the server is implemented using Ktor.
  3. Dependency Injection: In this chapter, you’ll take your next step toward implementing a better app that’s easier to test and modify. You’ll start by refactoring the Busso App in a world without Dagger or Hilt.
  4. Dependency Injection & Scopes: In this chapter, you’ll learn how Scope and dependency are related to each other. You’ll start by refactoring how SplashActivity uses Navigator. Next, you’ll define multiple ServiceLocator implementations, helping you understand how they depend on each other.
  5. Dependency Injection & Testability:In this chapter, you’ll use an architectural pattern — Model View Presenter — along with what you learned in the previous chapters to create a fully-testable app. You’ll use techniques that would work in a world without frameworks like Dagger or Hilt.

Section II: Introducing Dagger

In this section, you’ll 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.

Learn how to solve tricky dependencies using Dagger

You’ll learn how to deal with constructor, field and method injection with Dagger, how to simplify the implementation of @Module by using @Binds in cases when you have abstraction and its implementation, and how to use @Singleton to solve a very common problem.

  1. Hello, Dagger: In this chapter, you’ll 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.
  2. More About Injection: In this chapter, you’ll discover even more about dependency injection with Dagger. You’ll learn how to deal with constructor, field and method injection with Dagger.
  3. Working With Modules: In this chapter, you’ll learn how to use different Dagger @Modules in the same app, how to optimize start-up performances using Dagger’s Lazy interface, and how to avoid cycled dependencies using the Provider interface.
  4. More About Modules: In this chapter, you’ll learn more about modules. You’ll see the benefits of using the @Binds annotation in a @Module, how to provide existing objects, like Android Context, when optional bindings can help, and more.

Section III: Components & Scope Management

In this section, you’ll migrate the Busso App from the homemade framework to Dagger. In the process, you’ll learn how to migrate the existing ServiceLocators and Injectors to the equivalent Dagger @Modules and @Components, how to provide existing objects with a customized Builder for the @Component using @Component.Builder, and how to use @Component.Factory as a valid alternative to @Component.Builder.

The first migration will not be optimal — there will still be some fundamental aspects you will improve.

  1. Understanding Components: In this chapter, you’ll go back to working on the Busso App. You’ll learn how to migrate the existing ServiceLocators and Injectors to the equivalent Dagger @Modules and @Components, how to provide existing objects with a customized Builder for the @Component using @Component.Builder, and how to use @Component.Factory as a valid alternative to @Component.Builder.
  2. Components & Scopes: In this chapter, you’ll learn about the definition of a component and how it relates to containers. You’ll see what a lifecycle is, why it’s important, and what its relationship to the scope is. You’ll also learn more about @Singletons, and What a @Scope is, and how it improves your app’s performance.
  3. @Components Dependencies: In this chapter, you’ll learn even more about @Components and dependencies. In particular, you’ll learn why @Singleton is not so different from the other @Scopes, why you might need a different approach to managing component dependencies, and more.

Section IV: Advanced Dagger

In this section, you’ll dive deeper into the advanced features of Dagger like multi-binding. Multibinding is a very interesting feature of Dagger because it simplifies the integration of new features using a plugin pattern you’ll learn in this section.

You’ll implement a simple framework that allows you to integrate new services in the Busso app in a very simple and declarative way. You’ll learn all you need to know about multi-binding with Set and Map.

  1. Multibinding: In this chapter, you’ll learn what multi-binding is and how to use multi-binding with Set.
  2. Multibinding with Maps: In this chapter, you’ll learn how to use multi-binding with Map. You’ll learn how to configure multi-binding with Map and how to use fundamental type keys with @StringKey, @ClassKey, @IntKey, and @LongKey. You’ll also create a simple custom key and use @KeyMap to build complex custom keys.
  3. Dagger & Modularization: In this chapter, you’ll learn how to configure and use Dagger in multi-module apps.

Section V: Introducing Hilt

In the last section, you’ll learn everything you need to know about Hilt. Hilt is a dependency injection library for Android that reduces the boilerplate of doing manual dependency injection in your project.

Hilt is built on top of the DI library Dagger to benefit from the compile-time correctness, runtime performance, scalability, and Android Studio support that Dagger provides.

  1. Dagger & Android: In this chapter, you’ll learn how Dagger can help you automate dependency injection in your Android app and how to eliminate writing tedious and error-prone boilerplate code.
  2. Hilt – Dagger Made Easy: In this chapter, you’ll learn what is Hilt library and how it reduces the boilerplate of doing manual dependency injection in your project.
  3. Hilt & Architecture Components: In this chapter, you’ll learn about the extensions that Hilt provides for providing classes from other Jetpack libraries.
  4. Testing with Hilt: In this chapter, you’ll learn how Hilt makes testing your code easier.
  5. Appendix A – The Busso Server: In this chapter, you’ll look at how to implement dependency injection on the server using Koin.
  6. Appendix B – Assisted Injection: In this chapter, you’ll learn all about assisted injection with Dagger and Hilt.

About the Author

Massimo Carli has been working with Java since 1995 when he co-founded the first Italian magazine about this technology (http://www.mokabyte.it). After many years creating Java desktop and enterprise application, Massimo started to work in the mobile world. In 2001 he wrote his first book about J2ME. After many J2ME and Blackberry applications, he then started to work with Android in 2008. The same year Massimo wrote the first Italian book about Android; best seller on Amazon.it. That was the first of a series of 12 books. Massimo worked at Yahoo and Facebook and he’s actually working as Senior Engineer at Spotify. Massimo is a musical theatre lover and a supporter of the soccer team S.P.A.L.

Where to Go From Here?

Dagger by Tutorials, First Edition is 100% complete and available today! Like every one of our books, Dagger by Tutorials has been automatically added to the collections of all Ultimate Pro subscribers.

Want your own copy of Dagger by Tutorials? There are two ways you can enjoy this book:

  • Buy it individually: If you want to build up a custom library without a subscription, you can choose to buy the book individually. It’s available now for just $59.99 in our online store.
  • Get it as part an Ultimate Pro book and video subscription: Enjoy access to over 4,000+ videos and every single one of our 40+ professional mobile development books, including Dagger by Tutorials! Right now, you can get a full year’s Ultimate Pro subscription and save 20% off the cost of a regular monthly subscription. It’s simply the best investment for your mobile development career.

We hope you enjoy this first edition of Dagger by Tutorials. From the entire book team, thank you for your support!

Add a rating for this content

More like this

Contributors

Comments