All Projects → STAR-ZERO → dagger-tutorial

STAR-ZERO / dagger-tutorial

Licence: other
No description, website, or topics provided.

Programming Languages

kotlin
9241 projects

Dagger tutorial

Daggerの基本的なことを書いたシンプルなアプリ群です。

各Stepに分かれていて、それぞれ独立して実行可能です。自分で色々試してみてください。

指摘事項や質問があれば、Issueにお願いします

step1

Daggerを使ったシンプルなアプリです。

単純な@Component@Moduleを定義してるだけです。

step2

Scopeを使ったときにインスタンスがどう使われるかを試したアプリです。

@Singletonを使ったときにどうなるかを確認してみてください。

step3

@Componentdependenciesを使った、Componentの親子関係の定義です。

親と子それぞれでScopeを分けており、インスタンスの生存期間が異なります。

step4

@Subcomponentを使った、Componentの親子関係の定義です。

step3では子Componentに親Componentを設定する感じでしたが、step4では親Componentから子Componentを取得する感じになります。

step5

@Component.Builderを使ったサンプルです。

@BindsInstanceを使った依存解決になります。Moduleのコンストラクタ引数を使うより、@BindsInstanceを使うことが推奨されています。

step6

@Namedを使った、同じ型で違うインスタンスを依存解決する方法です。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].