Dagger 2 examples

AndroidDaggerDagger 2

Android Problem Overview


Dagger 2 is around the corner but the available examples wouldn't even compile right off the box, and the documentation is a copy-paste-replace from Dagger 1.

Does anyone have an example of a proper application working on Google's Dagger 2?

Android Solutions


Solution 1 - Android

I've just published sample app based on Gradle which integrates Dagger2, retrolambda, butterknife and lombok. You can find it here: https://github.com/mgrzechocinski/dagger2-example.

Hope it would help :)

Solution 2 - Android

I've just ported u2020-mvp app to Dagger 2. We use it as our sandbox app. Dagger 2 has nice implementation of scopes by the way. Components are really big deal. And it is based on u2021 made by Christian Gruber. You can check that as well.

Hope it helps :)

Solution 3 - Android

For anyone looking for a simple and straightforward way to just build a Dagger 2 project on Gradle/Android Studio, check out https://github.com/bytehala/dagger2-gradle-quickstart

In the commit messages, I also enumerate the steps to convert a fully functioning project to Dagger 2.

> The target audience for this project is anyone who has no experience with dependency injection.

No other library besides Butterknife is used.

WARNING The aim of this sample project is simplicity, not completeness. Only the following features were used:

  • @Module
  • @Component
  • @Injects
  • @Provides
  • @Singleton

Topics such as scopes, submodules, etc are left as an exercise.

Solution 4 - Android

CoffeeMaker sample without android: https://github.com/yongjhih/dagger2-sample

Steps:

git clone https://github.com/yongjhih/dagger2-sample
cd dagger2-sample
./gradlew execute

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMLProgrammer-CiMView Question on Stackoverflow
Solution 1 - Androidmateusz.grzechocinskiView Answer on Stackoverflow
Solution 2 - AndroidKirill BoyarshinovView Answer on Stackoverflow
Solution 3 - AndroidlemuelView Answer on Stackoverflow
Solution 4 - AndroidAndrew ChenView Answer on Stackoverflow