Pro Yearly is on sale from $80 to $50! »

android-multi-module-with-dagger

 android-multi-module-with-dagger

DroidKaigi2019
Day 01 11:20~
「マルチモジュールプロジェクトでの Dagger2を用いた Dependency Injection」
での発表資料です

サンプルコード
https://github.com/kgmyshin/Multi-Module-Project-With-Dagger

3c4e24fd827c789cb67a9f759f057b06?s=128

Shinnosuke Kugimiya

February 07, 2019
Tweet

Transcript

  1. X © DMM.com w %FQFOEFODZ*OKFDUJPOͱ͸ʢ؆୯ʹʣ w %BHHFS࠶ೖ໳ w %BHHFSͷ"OESPJEαϙʔτ࠶ೖ໳ w

    γϯάϧϞδϡʔϧͰͷ%BHHFSΛ༻͍ͨ%FQFOEFODZ*OKFDUJPO w ϚϧνϞδϡʔϧͰͷ%FQFOEFODZ*OKFDUJPOͷਏ͞ w %BHHFSΛ࢖ͬͯϚϧνϞδϡʔϧϓϩδΣΫτͰ%*Λ࣮ݱ͢Δ w %ZOBNJD'FBUVSF.PEVMF͕͋Δ࣌ͷ࿩ʢ͕࣌ؒ͋Ε͹ʣ "HFOEB ΰʔϧ ϚϧνϞδϡʔϧͰߏ੒͞ΕͨϓϩδΣΫτͰɺ %BHHFSΛ༻͍ͨ%FQFOEFODZ*OKFDUJPOΛߦ͏ࡍͷ ೰ΈϙΠϯτΛ஌ΓɺͦͷղܾࡦΛཧղ͢Δɻ
  2. !LHNZTIJO %SPJE,BJHJ ϚϧνϞδϡʔϧϓϩδΣΫτͰͷ %BHHFSΛ༻͍ͨ %FQFOEFODZ*OKFDUJPO

  3. X © DMM.com ࣗݾ঺հ w LHNZTIJOఝٶʢ͗͘Έ΍ʣ w "OESPJEΤϯδχΞ w ߹ಉձࣾ%..DPN$50ࣨॴଐ

  4. X © DMM.com ͜ͷηογϣϯͷΰʔϧ

  5. X © DMM.com ͜ͷηογϣϯͷΰʔϧ ϚϧνϞδϡʔϧͰߏ੒͞ΕͨϓϩδΣΫτͰɺ %BHHFSΛ༻͍ͨ%FQFOEFODZ*OKFDUJPOΛߦ͏ࡍͷ ೰ΈϙΠϯτΛ஌ΓɺͦͷղܾࡦΛཧղ͢Δɻ

  6. X © DMM.com BHFOEB

  7. X © DMM.com BHFOEB w %FQFOEFODZ*OKFDUJPOͱ͸ʢ؆୯ʹʣ w %BHHFS࠶ೖ໳ w %BHHFSͷ"OESPJEαϙʔτ࠶ೖ໳

    w γϯάϧϞδϡʔϧͰͷ%BHHFSΛ༻͍ͨ%FQFOEFODZ*OKFDUJPO w ϚϧνϞδϡʔϧͰͷ%FQFOEFODZ*OKFDUJPOͷਏ͞ w %BHHFSΛ࢖ͬͯϚϧνϞδϡʔϧϓϩδΣΫτͰ%*Λ࣮ݱ͢Δ w %ZOBNJD'FBUVSF.PEVMF͕͋Δ࣌ͷ࿩
  8. X © DMM.com ൃදʹೖΔલʹ ΋͠ηογϣϯΛฉ͍ͯΔதͰɺ Θ͔Βͳ͍ͱ͜ΖͳͲͰ͖ͯ·ͨ͠Βɺ ͥͻ%..DPNͷϒʔε·Ͱ͓ӽ͍ͩ͘͠͞ʂ

  9. X © DMM.com %FQFOEFODZ*OKFDUJPOͱ͸

  10. X © DMM.com %FQFOEFODZ*OKFDUJPOͱ͸ʢ؆୯ʹʣ ҰݴͰɻ ʮґଘΦϒδΣΫτʯΛʮ஫ೖʯ͢ΔσβΠϯύλʔϯͰ͢ɻ

  11. X © DMM.com %FQFOEFODZ*OKFDUJPOͱ͸ʢ؆୯ʹʣ internal class AllergenRepositoryImpl : AllergenRepository {

    private val apiClient = ApiClient() override fun findAll( ): Single<List<Allergen>> = apiClient.getAllergens() override fun findById( allergenId: AllergenId ): Maybe<Allergen> = apiClient.getAllergen(allergenId.value) } %*͠ͳ͍
  12. X © DMM.com %FQFOEFODZ*OKFDUJPOͱ͸ʢ؆୯ʹʣ internal class AllergenRepositoryImpl @Inject constructor( private

    val apiClient: ApiClient ) : AllergenRepository { override fun findAll( ): Single<List<Allergen>> = apiClient.getAllergens() override fun findById( allergenId: AllergenId ): Maybe<Allergen> = apiClient.getAllergen(allergenId.value) } internal class AllergenRepositoryImpl : AllergenRepository { private val apiClient = ApiClient() override fun findAll( ): Single<List<Allergen>> = apiClient.getAllergens() override fun findById( allergenId: AllergenId ): Maybe<Allergen> = apiClient.getAllergen(allergenId.value) } %*͠ͳ͍ %*͢Δ
  13. X © DMM.com %FQFOEFODZ*OKFDUJPOͱ͸ʢ؆୯ʹʣ internal class AllergenRepositoryImpl @Inject constructor( private

    val apiClient: ApiClient ) : AllergenRepository { override fun findAll( ): Single<List<Allergen>> = apiClient.getAllergens() override fun findById( allergenId: AllergenId ): Maybe<Allergen> = apiClient.getAllergen(allergenId.value) } internal class AllergenRepositoryImpl : AllergenRepository { private val apiClient = ApiClient() override fun findAll( ): Single<List<Allergen>> = apiClient.getAllergens() override fun findById( allergenId: AllergenId ): Maybe<Allergen> = apiClient.getAllergen(allergenId.value) } %*͠ͳ͍ %*͢Δ
  14. X © DMM.com %FQFOEFODZ*OKFDUJPOͱ͸ʢ؆୯ʹʣ ϝϦοτ w ݁߹͕ૄʹͳΔ w ୯ମςετ͕͠΍͍͢ w

    ಛఆͷϥΠϒϥϦ΍ϑϨʔϜϫʔΫ΁ͷґଘ౓ΛԼ͛Δ͜ͱ͕Ͱ ͖Δ
  15. X © DMM.com ಛఆͷϥΠϒϥϦ΍ϑϨʔϜϫʔΫ΁ͷґଘ౓ΛԼ͛Δ͜ͱ͕Ͱ͖Δ w 7PMMFZPS3FUSPpUPS,UPS$MJFOU w 1JDBTTPPS(MJEF ͳͲͳͲͷґଘ౓Λ۩৅Օॴʹด͡ࠐΊΔ͜ͱͰɺ༰қʹϥΠϒ ϥϦΛ੾Γସ͑Δ͜ͱ͕Ͱ͖Δɻ

  16. X © DMM.com ΑΓ͔ͬ͠Γ஌Γ͍ͨํ͸ʜ %BZdࠓ೔͔Β࢝ΊΔґଘੑͷ஫ೖCZLPCBLFJTBO

  17. X © DMM.com %BHHFS࠶ೖ໳

  18. X © DMM.com ΞϓϦέʔγϣϯͰ%*Λ࣮ݱ͢Δʹ͸ʁ

  19. X © DMM.com ΞϓϦέʔγϣϯͰ%*Λ࣮ݱ͢Δʹ͸ʁ

  20. X © DMM.com ΞϓϦέʔγϣϯͰ%*Λ࣮ݱ͢Δʹ͸ʁ

  21. X © DMM.com ΞϓϦέʔγϣϯͰ%*Λ࣮ݱ͢Δʹ͸ʁ

  22. X © DMM.com ΞϓϦέʔγϣϯͰ%*Λ࣮ݱ͢Δʹ͸ʁ

  23. X © DMM.com ΞϓϦέʔγϣϯͰ%*Λ࣮ݱ͢Δʹ͸ʁ ΞϓϦέʔγϣϯͰ%*Λ࣮ݱ͢Δʹ͸ Ͳ͜ʹɹͳʹΛ *OKFDU͢Δ͔Λ໢ཏ͢Δඞཁ͕͋Δɻ

  24. X © DMM.com %BHHFSͰ͸ ΞϓϦέʔγϣϯͰ%*Λ࣮ݱ͢Δʹ͸ Ͳ͜ʹɹͳʹΛ *OKFDU͢Δ͔Λ໢ཏ͢Δඞཁ͕͋Δɻ

  25. X © DMM.com %BHHFSͰ͸ ΞϓϦέʔγϣϯͰ%*Λ࣮ݱ͢Δʹ͸ Ͳ͜ʹɹͳʹΛ *OKFDU͢Δ͔Λ໢ཏ͢Δඞཁ͕͋Δɻ

  26. X © DMM.com %BHHFSͰ͸ ΞϓϦέʔγϣϯͰ%*Λ࣮ݱ͢Δʹ͸ Ͳ͜ʹɹͳʹΛ *OKFDU͢Δ͔Λ໢ཏ͢Δඞཁ͕͋Δɻ

  27. X © DMM.com %BHHFSͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ

     ֤ॴͰJOKFDU %BHHFSΛ࢖࣮ͬͨ૷ͷྲྀΕ ˞ɹखॱ̏͸৔߹ʹΑΔ͕ɺ͜͜Ͱ͸؆ུԽͷͨΊʹ͜ͷखॱʹݻఆ͢Δ ˞ɹҎ߱ͷྫͰ͸'SBHNFOU΁ͷ*OKFDUΛର৅ͱ͍ͯ͠Δ͕ɺଞͷΫϥεʹஔ͖׵͑ͯ΋໰୊ͳ͍
  28. X © DMM.com %BHHFSͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ

     ֤ॴͰJOKFDU %BHHFSΛ࢖࣮ͬͨ૷ͷྲྀΕ ˞ɹखॱ̏͸৔߹ʹΑΔ͕ɺ͜͜Ͱ͸؆ུԽͷͨΊʹ͜ͷखॱʹݻఆ͢Δ ˞ɹҎ߱ͷྫͰ͸'SBHNFOU΁ͷ*OKFDUΛର৅ͱ͍ͯ͠Δ͕ɺଞͷΫϥεʹஔ͖׵͑ͯ΋໰୊ͳ͍
  29. X © DMM.com ᶃ.PEVMFΛ༻ҙ͢Δ )PHFܕͷΠϯελϯεΛ͍ͩ͘͞ IPHFΛͲ͏ͧ ʮͳʹΛఏڙ͢Δ͔ʁʯܕͱΠϯελϯεͷඥ෇͚Λߦ͏

  30. X © DMM.com ᶃ.PEVMFΛ༻ҙ͢Δ @Module internal abstract class GreetingModule {

    @Binds abstract fun provideGreeter(impl: GreeterImpl): Greeter } @Module internal class CounterModule { @Singleton @Provides fun provideCounter(): Counter = CounterImpl() } .PEVMFͷॻ͖ํͷྫܕͱΠϯελϯεͷඥ෇͚Λߦ͏
  31. X © DMM.com ᶃ.PEVMFΛ༻ҙ͢Δ @Module internal abstract class GreetingModule {

    @Binds abstract fun provideGreeter(impl: GreeterImpl): Greeter } @Module internal class CounterModule { @Singleton @Provides fun provideCounter(): Counter = CounterImpl() } .PEVMFͷॻ͖ํͷྫܕͱΠϯελϯεͷඥ෇͚Λߦ͏
  32. X © DMM.com ᶃ.PEVMFΛ༻ҙ͢Δ @Module internal abstract class GreetingModule {

    @Binds abstract fun provideGreeter(impl: GreeterImpl): Greeter } @Module internal class CounterModule { @Singleton @Provides fun provideCounter(): Counter = CounterImpl() } .PEVMFͷॻ͖ํͷྫܕͱΠϯελϯεͷඥ෇͚Λߦ͏
  33. X © DMM.com ᶃ.PEVMFΛ༻ҙ͢Δ @Module internal abstract class GreetingModule {

    @Binds abstract fun provideGreeter(impl: GreeterImpl): Greeter } @Module internal class CounterModule { @Singleton @Provides fun provideCounter(): Counter = CounterImpl() } .PEVMFͷॻ͖ํͷྫ
  34. X © DMM.com ᶃ.PEVMFΛ༻ҙ͢Δ @Module internal abstract class GreetingModule {

    @Binds abstract fun provideGreeter(impl: GreeterImpl): Greeter } @Module internal class CounterModule { @Singleton @Provides fun provideCounter(): Counter = CounterImpl() } .PEVMFͷॻ͖ํͷྫܕͱΠϯελϯεͷඥ෇͚Λߦ͏
  35. X © DMM.com %BHHFSͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ

     ֤ॴͰJOKFDU %BHHFSΛ࢖࣮ͬͨ૷ͷྲྀΕ ˞ɹखॱ̏͸৔߹ʹΑΔ͕ɺ͜͜Ͱ͸؆ུԽͷͨΊʹ͜ͷखॱʹݻఆ͢Δ ˞ɹҎ߱ͷྫͰ͸'SBHNFOU΁ͷ*OKFDUΛର৅ͱ͍ͯ͠Δ͕ɺଞͷΫϥεʹஔ͖׵͑ͯ΋໰୊ͳ͍
  36. X © DMM.com %BHHFSͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ

     ֤ॴͰJOKFDU %BHHFSΛ࢖࣮ͬͨ૷ͷྲྀΕ ˞ɹखॱ̏͸৔߹ʹΑΔ͕ɺ͜͜Ͱ͸؆ུԽͷͨΊʹ͜ͷखॱʹݻఆ͢Δ ˞ɹҎ߱ͷྫͰ͸'SBHNFOU΁ͷ*OKFDUΛର৅ͱ͍ͯ͠Δ͕ɺଞͷΫϥεʹஔ͖׵͑ͯ΋໰୊ͳ͍
  37. X © DMM.com ᶄ$PNQPOFOUΛ༻ҙ͢Δ ΞϓϦέʔγϣϯͰ%*Λ࣮ݱ͢Δʹ͸ Ͳ͜ʹɹͳʹΛ *OKFDU͢Δ͔Λ໢ཏ͢Δඞཁ͕͋Δɻ

  38. X © DMM.com ᶄ$PNQPOFOUΛ༻ҙ͢Δ ΞϓϦέʔγϣϯͰ%*Λ࣮ݱ͢Δʹ͸ Ͳ͜ʹɹͳʹΛ *OKFDU͢Δ͔Λ໢ཏ͢Δඞཁ͕͋Δɻ $PNQPOFOUʹ͸ʮͳʹΛఏڙ͢Δ͔ʯҎ֎Λॻ͘

  39. X © DMM.com ᶄ$PNQPOFOUΛ༻ҙ͢Δ ΞϓϦέʔγϣϯͰ%*Λ࣮ݱ͢Δʹ͸ Ͳ͜ʹɹͳʹΛ *OKFDU͢Δ͔Λ໢ཏ͢Δඞཁ͕͋Δɻ $PNQPOFOUʹ͸ʮͳʹΛఏڙ͢Δ͔ʯҎ֎Λॻ͘ ʮͲ͜ʹఏڙ͢Δ͔ʯΛओʹॻ͘

  40. X © DMM.com ᶄ$PNQPOFOUΛ༻ҙ͢Δ @Singleton @Component(modules = [GreetingModule::class]) interface GreetingComponent

    { fun inject(activity: GreetingActivity) fun inject(fragment: GreetingFragment) fun greeter(): Greeter } $PNQPOFOUͷॻ͖ํͷྫJOKFDUઌΛҾ਺ʹͨؔ͠਺Λఆٛ͢Δ
  41. X © DMM.com ᶄ$PNQPOFOUΛ༻ҙ͢Δ @Singleton @Component(modules = [GreetingModule::class]) interface GreetingComponent

    { fun inject(activity: GreetingActivity) fun inject(fragment: GreetingFragment) fun greeter(): Greeter } $PNQPOFOUͷॻ͖ํͷྫJOKFDUઌΛҾ਺ʹͨؔ͠਺Λఆٛ͢Δ
  42. X © DMM.com ᶄ$PNQPOFOUΛ༻ҙ͢Δ @Singleton @Component(modules = [GreetingModule::class]) interface GreetingComponent

    { fun inject(activity: GreetingActivity) fun inject(fragment: GreetingFragment) fun greeter(): Greeter } $PNQPOFOUͷॻ͖ํͷྫJOKFDUઌΛҾ਺ʹͨؔ͠਺Λఆٛ͢Δ
  43. X © DMM.com ᶄ$PNQPOFOUΛ༻ҙ͢Δ @Singleton @Component(modules = [GreetingModule::class]) interface GreetingComponent

    { fun inject(activity: GreetingActivity) fun inject(fragment: GreetingFragment) fun greeter(): Greeter } $PNQPOFOUͷॻ͖ํͷྫJOKFDUઌΛҾ਺ʹͨؔ͠਺Λఆٛ͢Δ
  44. X © DMM.com %BHHFSͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ

     ֤ॴͰJOKFDU %BHHFSΛ࢖࣮ͬͨ૷ͷྲྀΕ ˞ɹखॱ̏͸৔߹ʹΑΔ͕ɺ͜͜Ͱ͸؆ུԽͷͨΊʹ͜ͷखॱʹݻఆ͢Δ ˞ɹҎ߱ͷྫͰ͸'SBHNFOU΁ͷ*OKFDUΛର৅ͱ͍ͯ͠Δ͕ɺଞͷΫϥεʹஔ͖׵͑ͯ΋໰୊ͳ͍
  45. X © DMM.com %BHHFSͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ

     ֤ॴͰJOKFDU %BHHFSΛ࢖࣮ͬͨ૷ͷྲྀΕ ˞ɹखॱ̏͸৔߹ʹΑΔ͕ɺ͜͜Ͱ͸؆ུԽͷͨΊʹ͜ͷखॱʹݻఆ͢Δ ˞ɹҎ߱ͷྫͰ͸'SBHNFOU΁ͷ*OKFDUΛର৅ͱ͍ͯ͠Δ͕ɺଞͷΫϥεʹஔ͖׵͑ͯ΋໰୊ͳ͍
  46. X © DMM.com ᶅ"QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ class Application : android.app.Application(){ lateinit var

    appComponent: AppComponent override fun onCreate() { super.onCreate() appComponent = DaggerAppComponent.create() } }
  47. X © DMM.com ᶅ"QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ class Application : android.app.Application(){ lateinit var

    appComponent: AppComponent override fun onCreate() { super.onCreate() appComponent = DaggerAppComponent.create() } }
  48. X © DMM.com %BHHFSͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ

     ֤ॴͰJOKFDU %BHHFSΛ࢖࣮ͬͨ૷ͷྲྀΕ ˞ɹखॱ̏͸৔߹ʹΑΔ͕ɺ͜͜Ͱ͸؆ུԽͷͨΊʹ͜ͷखॱʹݻఆ͢Δ ˞ɹҎ߱ͷྫͰ͸'SBHNFOU΁ͷ*OKFDUΛର৅ͱ͍ͯ͠Δ͕ɺଞͷΫϥεʹஔ͖׵͑ͯ΋໰୊ͳ͍
  49. X © DMM.com %BHHFSͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ

     ֤ॴͰJOKFDU %BHHFSΛ࢖࣮ͬͨ૷ͷྲྀΕ ˞ɹखॱ̏͸৔߹ʹΑΔ͕ɺ͜͜Ͱ͸؆ུԽͷͨΊʹ͜ͷखॱʹݻఆ͢Δ ˞ɹҎ߱ͷྫͰ͸'SBHNFOU΁ͷ*OKFDUΛର৅ͱ͍ͯ͠Δ͕ɺଞͷΫϥεʹஔ͖׵͑ͯ΋໰୊ͳ͍
  50. X © DMM.com ᶆ֤ॴͰ*OKFDU͢Δ class MainFragment : Fragment() { @Inject

    lateinit var greeter: Greeter override fun onAttach(context: Context?) { super.onAttach(context) (requireActivity().application as Application) .appComponent.inject(this) } : }
  51. X © DMM.com ᶆ֤ॴͰ*OKFDU͢Δ class MainFragment : Fragment() { @Inject

    lateinit var greeter: Greeter override fun onAttach(context: Context?) { super.onAttach(context) (requireActivity().application as Application) .appComponent.inject(this) } : }
  52. X © DMM.com ᶆ֤ॴͰ*OKFDU͢Δ class MainFragment : Fragment() { @Inject

    lateinit var greeter: Greeter override fun onAttach(context: Context?) { super.onAttach(context) (requireActivity().application as Application) .appComponent.inject(this) } : }
  53. X © DMM.com %BHHFSͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ

     ֤ॴͰJOKFDU %BHHFSΛ࢖࣮ͬͨ૷ͷྲྀΕ ˞ɹखॱ̏͸৔߹ʹΑΔ͕ɺ͜͜Ͱ͸؆ུԽͷͨΊʹ͜ͷखॱʹݻఆ͢Δ ˞ɹҎ߱ͷྫͰ͸'SBHNFOU΁ͷ*OKFDUΛର৅ͱ͍ͯ͠Δ͕ɺଞͷΫϥεʹஔ͖׵͑ͯ΋໰୊ͳ͍
  54. X © DMM.com %BHHFS"OESPJE࠶ೖ໳

  55. X © DMM.com %BHHFS"OESPJEͷϞνϕʔγϣϯ class MainFragment : Fragment() { @Inject

    lateinit var greeter: Greeter override fun onAttach(context: Context?) { super.onAttach(context) (requireActivity().application as Application) .appComponent.inject(this) } : }
  56. X © DMM.com %BHHFS"OESPJEͷϞνϕʔγϣϯ class MainFragment : Fragment() { @Inject

    lateinit var greeter: Greeter override fun onAttach(context: Context?) { super.onAttach(context) (requireActivity().application as Application) .appComponent.inject(this) } : } *OKFDU͞ΕΔଆ͕ɺ*OKFDUPSʹ͍ͭͯͷৄࡉΛ஌ͬͯ͠·͍ͬͯΔɻ
  57. X © DMM.com %BHHFS"OESPJEͷϞνϕʔγϣϯ class MainFragment : Fragment() { @Inject

    lateinit var greeter: Greeter override fun onAttach(context: Context?) { super.onAttach(context) (requireActivity().application as Application) .appComponent.inject(this) } : } *OKFDU͞ΕΔଆ͕ɺ*OKFDUPSʹ͍ͭͯͷৄࡉΛ஌ͬͯ͠·͍ͬͯΔɻ Ͳ͜ʹ*OKFDUPS͕͋Δͷ͔ʁͲͷ*OKFDUPS͕ࣗ෼Λ*OKFDUͰ͖Δͷ͔ʁͳͲ
  58. X © DMM.com %BHHFS"OESPJEͷϞνϕʔγϣϯ class MainFragment : Fragment() { @Inject

    lateinit var greeter: Greeter override fun onAttach(context: Context?) { AndroidSupportInjection.inject(this) super.onAttach(context) } : } ͜͏͢Ε͹ɺྑͦ͞͏
  59. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ

     ֤ॴͰJOKFDU %BHHFSΛ࢖࣮ͬͨ૷ͷྲྀΕ
  60. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ /FX 

     $PNQPOFOUΛ༻ҙ͢Δ 6QEBUFE   "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ 6QEBUFE   ֤ॴͰJOKFDU 6QEBUFE EBHHFSBOESPJEΛ࢖࣮ͬͨ૷ͷྲྀΕ
  61. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ

     "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU EBHHFSBOESPJEΛ࢖࣮ͬͨ૷ͷྲྀΕ
  62. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ

     "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU EBHHFSBOESPJEΛ࢖࣮ͬͨ૷ͷྲྀΕ
  63. X © DMM.com ᶃ.PEVMFΛ༻ҙ͢Δ @Module abstract class AppModule { @Binds

    abstract fun messageProvider(impl: MessageProviderImpl): MessageProvider }
  64. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ

     "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU EBHHFSBOESPJEΛ࢖࣮ͬͨ૷ͷྲྀΕ
  65. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ

     "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU EBHHFSBOESPJEΛ࢖࣮ͬͨ૷ͷྲྀΕ
  66. X © DMM.com ᶄ'SBHNFOU.PEVMFΛ༻ҙ͢Δ @Module abstract class MainFragmentModule { @ContributesAndroidInjector

    abstract fun mainFragment(): MainFragment }
  67. X © DMM.com ᶄ'SBHNFOU.PEVMFΛ༻ҙ͢Δ @Module abstract class MainFragmentModule { @ContributesAndroidInjector

    abstract fun mainFragment(): MainFragment }
  68. X © DMM.com ᶄ'SBHNFOU.PEVMFΛ༻ҙ͢Δ @Module abstract class MainFragmentModule { @ContributesAndroidInjector

    abstract fun mainFragment(): MainFragment }
  69. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ

     "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU EBHHFSBOESPJEΛ࢖࣮ͬͨ૷ͷྲྀΕ
  70. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ

     "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU EBHHFSBOESPJEΛ࢖࣮ͬͨ૷ͷྲྀΕ
  71. X © DMM.com ᶅ$PNQPOFOUΛ༻ҙ͢Δ @Singleton @Component( modules = [ AndroidInjectionModule::class,

    AppModule::class, MainFragmentModule::class ] ) interface AppComponent : AndroidInjector<Application>
  72. X © DMM.com ᶅ$PNQPOFOUΛ༻ҙ͢Δ @Singleton @Component( modules = [ AndroidInjectionModule::class,

    AppModule::class, MainFragmentModule::class ] ) interface AppComponent : AndroidInjector<Application>
  73. X © DMM.com ᶅ$PNQPOFOUΛ༻ҙ͢Δ @Singleton @Component( modules = [ AndroidInjectionModule::class,

    AppModule::class, MainFragmentModule::class ] ) interface AppComponent : AndroidInjector<Application>
  74. X © DMM.com ᶅ$PNQPOFOUΛ༻ҙ͢Δ @Singleton @Component( modules = [ AndroidInjectionModule::class,

    AppModule::class, MainFragmentModule::class ] ) interface AppComponent : AndroidInjector<Application>
  75. X © DMM.com ᶅ$PNQPOFOUΛ༻ҙ͢Δ @Singleton @Component( modules = [ AndroidInjectionModule::class,

    AppModule::class, MainFragmentModule::class ] ) interface AppComponent : AndroidInjector<Application> Ͳ͜ʹ*OKFDU͢Δ͔͸ɺ'SBHNFOU.PEVMF΍"OESPJE*OKFDUPSʹ ୅ସ͞ΕͯΔͷͰॻ͔ͳ͍
  76. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ

     "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU EBHHFSBOESPJEΛ࢖࣮ͬͨ૷ͷྲྀΕ
  77. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ

     "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU EBHHFSBOESPJEΛ࢖࣮ͬͨ૷ͷྲྀΕ
  78. X © DMM.com ᶆ"QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ class Application : android.app.Application(), HasSupportFragmentInjector {

    @Inject lateinit var dispatchingFragmentInjector: DispatchingAndroidInjector<Fragment> override fun supportFragmentInjector(): AndroidInjector<Fragment> = dispatchingFragmentInjector override fun onCreate() { super.onCreate() DaggerAppComponent.create().inject(this) } }
  79. X © DMM.com ᶆ"QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ class Application : android.app.Application(), HasSupportFragmentInjector {

    @Inject lateinit var dispatchingFragmentInjector: DispatchingAndroidInjector<Fragment> override fun supportFragmentInjector(): AndroidInjector<Fragment> = dispatchingFragmentInjector override fun onCreate() { super.onCreate() DaggerAppComponent.create().inject(this) } }
  80. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ

     "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU EBHHFSBOESPJEΛ࢖࣮ͬͨ૷ͷྲྀΕ
  81. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ

     "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU EBHHFSBOESPJEΛ࢖࣮ͬͨ૷ͷྲྀΕ
  82. X © DMM.com ᶇ֤ॴͰ*OKFDU class MainFragment : Fragment() { @Inject

    lateinit var messageProvider: MessageProvider override fun onAttach(context: Context?) { AndroidSupportInjection.inject(this) super.onAttach(context) } … }
  83. X © DMM.com ᶇ֤ॴͰ*OKFDU class MainFragment : Fragment() { @Inject

    lateinit var messageProvider: MessageProvider override fun onAttach(context: Context?) { AndroidSupportInjection.inject(this) super.onAttach(context) } … }
  84. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ

     "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU EBHHFSBOESPJEΛ࢖࣮ͬͨ૷ͷྲྀΕ
  85. X © DMM.com ࢓૊Έ $PNQPOFOU w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏ w

    .BJO"DUJWJUZʹJOKFDU͢Δํ๏ w 4VC"DUJWJUZʹJOKFDU͢Δํ๏
  86. X © DMM.com ࢓૊Έ $PNQPOFOU w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏ w

    .BJO"DUJWJUZʹJOKFDU͢Δํ๏ w 4VC"DUJWJUZʹJOKFDU͢Δํ๏ w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏ w .BJO"DUJWJUZʹJOKFDU͢Δํ๏ w 4VC"DUJWJUZʹJOKFDU͢Δํ๏
  87. X © DMM.com ࢓૊Έ $PNQPOFOU w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏ w

    .BJO"DUJWJUZʹJOKFDU͢Δํ๏ w 4VC"DUJWJUZʹJOKFDU͢Δํ๏ w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏
  88. X © DMM.com ࢓૊Έ $PNQPOFOU w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏ w

    .BJO"DUJWJUZʹJOKFDU͢Δํ๏ w 4VC"DUJWJUZʹJOKFDU͢Δํ๏ w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏ class Application : HasSupportFragmentInjector { @Inject lateinit var dispatchingFragmentInjector … DaggerAppComponent.create().inject(this) … }
  89. X © DMM.com class Application : HasSupportFragmentInjector { @Inject lateinit

    var dispatchingFragmentInjector } ࢓૊Έ $PNQPOFOU w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏ w .BJO"DUJWJUZʹJOKFDU͢Δํ๏ w 4VC"DUJWJUZʹJOKFDU͢Δํ๏ w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏
  90. X © DMM.com ࢓૊Έ class Application : HasSupportFragmentInjector { @Inject

    lateinit var dispatchingFragmentInjector } w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏
  91. X © DMM.com ࢓૊Έ class Application : HasSupportFragmentInjector { @Inject

    lateinit var dispatchingFragmentInjector } w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏ class MainFragment : Fragment() { ɹɹ… AndroidSupportInjection.inject(this) … }
  92. X © DMM.com ࢓૊Έ class Application : HasSupportFragmentInjector { @Inject

    lateinit var dispatchingFragmentInjector } w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏ class MainFragment : Fragment() { ɹɹ… AndroidSupportInjection.inject(this) … } class MainActivity : AppCompatActivity() { … } HasSupportFragmentInjectorΛ࣮૷ͯ͠Δ͔ʁ
  93. X © DMM.com ࢓૊Έ class Application : HasSupportFragmentInjector { @Inject

    lateinit var dispatchingFragmentInjector } w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏ class MainFragment : Fragment() { ɹɹ… AndroidSupportInjection.inject(this) … } class MainActivity : AppCompatActivity() { … } HasSupportFragmentInjectorΛ࣮૷ͯ͠Δ͔ʁ
  94. X © DMM.com ࢓૊Έ class Application : HasSupportFragmentInjector { @Inject

    lateinit var dispatchingFragmentInjector } w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏ class MainFragment : Fragment() { ɹɹ… AndroidSupportInjection.inject(this) … } class MainActivity : AppCompatActivity() { … } HasSupportFragmentInjectorΛ࣮૷ͯ͠Δ͔ʁ
  95. X © DMM.com ࢓૊Έ class MainFragment : Fragment() { ɹɹ…

    AndroidSupportInjection.inject(this) … } class MainActivity : AppCompatActivity() { … } HasSupportFragmentInjectorΛ࣮૷ͯ͠Δ͔ʁ class Application : HasSupportFragmentInjector { @Inject lateinit var dispatchingFragmentInjector } w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏
  96. X © DMM.com class Application : HasSupportFragmentInjector { @Inject lateinit

    var dispatchingFragmentInjector } w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏ ࢓૊Έ class MainFragment : Fragment() { ɹɹ… AndroidSupportInjection.inject(this) … } class MainActivity : AppCompatActivity() { … } HasSupportFragmentInjectorΛ࣮૷ͯ͠Δ͔ʁ
  97. X © DMM.com class Application : HasSupportFragmentInjector { @Inject lateinit

    var dispatchingFragmentInjector } w .BJO'SBHNFOUʹJOKFDU͢Δํ๏ w 4VC'SBHNFOUʹJOKFDU͢Δํ๏ ࢓૊Έ class MainFragment : Fragment() { ɹɹ… AndroidSupportInjection.inject(this) … } class MainActivity : AppCompatActivity() { … } HasSupportFragmentInjectorΛ࣮૷ͯ͠Δ͔ʁ
  98. X © DMM.com ϚϧνϞδϡʔϧͷ%*Ͱͷਏ͞

  99. X © DMM.com ϚϧνϞδϡʔϧͰͷ%* BQQ DPVOUFS HSFFUJOH ͜͏͍͏΋ͷΛ࡞Δ

  100. X © DMM.com ϚϧνϞδϡʔϧͰͷ%* ͜͏͍͏΋ͷΛ࡞Δ BQQ DPVOUFS HSFFUJOH $PNQPOFOU͸ͦΕͧΕͰ࣋ͭ

  101. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ

     "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ
  102. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ

     "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ
  103. X © DMM.com ᶆ"QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ class Application : HasSupportFragmentInjector, … {

    @Inject lateinit var dispatchingFragmentInjector DispatchingAndroidInjector<Fragment>() override fun supportFragmentInjector(): AndroidInjector<Fragment> = dispatchingFragmentInjector override fun onCreate() { super.onCreate() DaggerCounterComponent.create().inject(this) DaggerGreetingComponent.create().inject(this) … } }
  104. X © DMM.com ᶆ"QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ class Application : HasSupportFragmentInjector, … {

    @Inject lateinit var dispatchingFragmentInjector DispatchingAndroidInjector<Fragment>() override fun supportFragmentInjector(): AndroidInjector<Fragment> = dispatchingFragmentInjector override fun onCreate() { super.onCreate() DaggerCounterComponent.create().inject(this) DaggerGreetingComponent.create().inject(this) … } }
  105. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ

     "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ
  106. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  $PNQPOFOUΛ༻ҙ͢Δ

     "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ
  107. X © DMM.com ᶇ֤ॴͰ*OKFDU class CounterFragment : Fragment() { @Inject

    lateinit var counter: Counter override fun onAttach(context: Context?) { AndroidSupportInjection.inject(this) super.onAttach(context) } … } class GreetingFragment : Fragment() { @Inject lateinit var greeter: Greeter override fun onAttach(context: Context?) { AndroidSupportInjection.inject(this) super.onAttach(context) } … }
  108. X © DMM.com ᶇ֤ॴͰ*OKFDU class CounterFragment : Fragment() { @Inject

    lateinit var counter: Counter override fun onAttach(context: Context?) { AndroidSupportInjection.inject(this) super.onAttach(context) } … } class GreetingFragment : Fragment() { @Inject lateinit var greeter: Greeter override fun onAttach(context: Context?) { AndroidSupportInjection.inject(this) super.onAttach(context) } … }
  109. X © DMM.com Ͳ͏ͳΔ͔ʁ $PVOUFS'SBHNFOU (SFFUJOH'SBHNFOU

  110. X © DMM.com Ͳ͏ͳΔ͔ʁ $PVOUFS'SBHNFOU (SFFUJOH'SBHNFOU

  111. X © DMM.com $PNQPOFOUΛॳظԽͷॱ൪ΛೖΕସ͑ͯΈΔͱ class Application : HasSupportFragmentInjector, … {

    @Inject lateinit var dispatchingFragmentInjector DispatchingAndroidInjector<Fragment>() override fun supportFragmentInjector(): AndroidInjector<Fragment> = dispatchingFragmentInjector override fun onCreate() { super.onCreate() DaggerCounterComponent.create().inject(this) DaggerGreetingComponent.create().inject(this) … } }
  112. X © DMM.com $PNQPOFOUΛॳظԽͷॱ൪ΛೖΕସ͑ͯΈΔͱ class Application : HasSupportFragmentInjector, … {

    @Inject lateinit var dispatchingFragmentInjector DispatchingAndroidInjector<Fragment>() override fun supportFragmentInjector(): AndroidInjector<Fragment> = dispatchingFragmentInjector override fun onCreate() { super.onCreate() DaggerGreetingComponent.create().inject(this) DaggerCounterComponent.create().inject(this) … } }
  113. X © DMM.com Ͳ͏ͳΔ͔ʁ $PVOUFS'SBHNFOU (SFFUJOH'SBHNFOU

  114. X © DMM.com $SBTI͢Δཧ༝ class Application : HasSupportFragmentInjector, … {

    @Inject lateinit var dispatchingFragmentInjector DispatchingAndroidInjector<Fragment>() … override fun onCreate() { super.onCreate() DaggerCounterComponent.create().inject(this) DaggerGreetingComponent.create().inject(this) … } }
  115. X © DMM.com $SBTI͢Δཧ༝ class Application : HasSupportFragmentInjector, … {

    @Inject lateinit var dispatchingFragmentInjector DispatchingAndroidInjector<Fragment>() … override fun onCreate() { super.onCreate() DaggerCounterComponent.create().inject(this) DaggerGreetingComponent.create().inject(this) … } }
  116. X © DMM.com $SBTI͢Δཧ༝ class Application : HasSupportFragmentInjector, … {

    @Inject lateinit var dispatchingFragmentInjector DispatchingAndroidInjector<Fragment>() … override fun onCreate() { super.onCreate() DaggerCounterComponent.create().inject(this) DaggerGreetingComponent.create().inject(this) … } }
  117. X © DMM.com class Application : HasSupportFragmentInjector { @Inject lateinit

    var dispatchingFragmentInjector } w (SFFUJOH'SBHNFOUʹJOKFDU͢Δํ๏ ࢓૊Έ class CounterFragment : Fragment() { ɹɹ… AndroidSupportInjection.inject(this) … }
  118. X © DMM.com class Application : HasSupportFragmentInjector { @Inject lateinit

    var dispatchingFragmentInjector } w (SFFUJOH'SBHNFOUʹJOKFDU͢Δํ๏ ࢓૊Έ class CounterFragment : Fragment() { ɹɹ… AndroidSupportInjection.inject(this) … }
  119. X © DMM.com %BHHFSΛ࢖ͬͯ ϚϧνϞδϡʔϧϓϩδΣΫτͰ %*Λ࣮ݱ͢Δ

  120. X © DMM.com վΊͯ՝୊ͱ͸ʁ ՝୊ "QQMJDBUJPOʹ'SBHNFOU༻ͷ*OKFDUPSΛҰ͔ͭ࣋ͯ͠ͳ͍ͨΊ ʹɺ*OKFDUPS্͕ॻ͖͞Εͯ͠·͏͜ͱ

  121. X © DMM.com վΊͯ՝୊ͱ͸ʁ ՝୊ "QQMJDBUJPOʹ'SBHNFOU༻ͷ*OKFDUPSΛҰ͔ͭ࣋ͯ͠ͳ͍ͨΊ ʹɺ*OKFDUPS্͕ॻ͖͞Εͯ͠·͏͜ͱ

  122. X © DMM.com վΊͯ՝୊ͱ͸ʁ ՝୊ "QQMJDBUJPOʹ'SBHNFOU༻ͷ*OKFDUPSΛҰ͔ͭ࣋ͯ͠ͳ͍ͨΊ ʹɺ*OKFDUPS্͕ॻ͖͞Εͯ͠·͏͜ͱ

  123. X © DMM.com "QQMJDBUJPOͰ࣋ͭͭͷ'SBHNFOU*OKFDUPS͕ɺෳ਺ͷ*OKFDUPS Λ࣋ͭΑ͏ʹ͢Δ ղܾࡦͷҰͭ

  124. X © DMM.com ͭͷ*OKFDUPSͷதͰෳ਺ͷ*OKFDUPSΛ࣋ͭΑ͏ʹ͢Δ

  125. X © DMM.com ͭͷ*OKFDUPSͷதͰෳ਺ͷ*OKFDUPSΛ࣋ͭΑ͏ʹ͢Δ

  126. X © DMM.com ͭͷ*OKFDUPSͷதͰෳ਺ͷ*OKFDUPSΛ࣋ͭΑ͏ʹ͢Δ

  127. X © DMM.com ͭͷ*OKFDUPSͷதͰෳ਺ͷ*OKFDUPSΛ࣋ͭΑ͏ʹ͢Δ

  128. X © DMM.com class ModuleInjector<T> : AndroidInjector<T> { private val

    injectors = mutableListOf<HasDispatchingInjector<T>>() fun addInjector(injector: HasDispatchingInjector<T>) { injectors.add(injector) } fun removeInjector(injector: HasDispatchingInjector<T>) { injectors.remove(injector) } … override fun inject(instance: T) { val wasInjected = injectors.any { it.dispatchingAndroidInjector().maybeInject(instance) } if (!wasInjected) { throw IllegalArgumentException("injection failed") } } } .PEVMF*OKFDUPS
  129. X © DMM.com class ModuleInjector<T> : AndroidInjector<T> { private val

    injectors = mutableListOf<HasDispatchingInjector<T>>() fun addInjector(injector: HasDispatchingInjector<T>) { injectors.add(injector) } fun removeInjector(injector: HasDispatchingInjector<T>) { injectors.remove(injector) } … override fun inject(instance: T) { val wasInjected = injectors.any { it.dispatchingAndroidInjector().maybeInject(instance) } if (!wasInjected) { throw IllegalArgumentException("injection failed") } } } .PEVMF*OKFDUPS
  130. X © DMM.com class ModuleInjector<T> : AndroidInjector<T> { private val

    injectors = mutableListOf<HasDispatchingInjector<T>>() fun addInjector(injector: HasDispatchingInjector<T>) { injectors.add(injector) } fun removeInjector(injector: HasDispatchingInjector<T>) { injectors.remove(injector) } … override fun inject(instance: T) { val wasInjected = injectors.any { it.dispatchingAndroidInjector().maybeInject(instance) } if (!wasInjected) { throw IllegalArgumentException("injection failed") } } } .PEVMF*OKFDUPS
  131. X © DMM.com class ModuleInjector<T> : AndroidInjector<T> { private val

    injectors = mutableListOf<HasDispatchingInjector<T>>() fun addInjector(injector: HasDispatchingInjector<T>) { injectors.add(injector) } fun removeInjector(injector: HasDispatchingInjector<T>) { injectors.remove(injector) } … override fun inject(instance: T) { val wasInjected = injectors.any { it.dispatchingAndroidInjector().maybeInject(instance) } if (!wasInjected) { throw IllegalArgumentException("injection failed") } } } .PEVMF*OKFDUPS interface HasDispatchingInjector<T> { fun dispatchingAndroidInjector(): DispatchingAndroidInjector<T> }
  132. X © DMM.com class ModuleInjector<T> : AndroidInjector<T> { private val

    injectors = mutableListOf<HasDispatchingInjector<T>>() fun addInjector(injector: HasDispatchingInjector<T>) { injectors.add(injector) } fun removeInjector(injector: HasDispatchingInjector<T>) { injectors.remove(injector) } … override fun inject(instance: T) { val wasInjected = injectors.any { it.dispatchingAndroidInjector().maybeInject(instance) } if (!wasInjected) { throw IllegalArgumentException("injection failed") } } } .PEVMF*OKFDUPS
  133. X © DMM.com class ModuleInjector<T> : AndroidInjector<T> { private val

    injectors = mutableListOf<HasDispatchingInjector<T>>() fun addInjector(injector: HasDispatchingInjector<T>) { injectors.add(injector) } fun removeInjector(injector: HasDispatchingInjector<T>) { injectors.remove(injector) } … override fun inject(instance: T) { val wasInjected = injectors.any { it.dispatchingAndroidInjector().maybeInject(instance) } if (!wasInjected) { throw IllegalArgumentException("injection failed") } } } .PEVMF*OKFDUPS
  134. X © DMM.com EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ NVMUJNPEVMF  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ 

    *OKFDUPSΛ༻ҙ͢Δ /FX   $PNQPOFOUΛ༻ҙ͢Δ 6QEBUFE   "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ 6QEBUFE   ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ
  135. X © DMM.com  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  *OKFDUPSΛ༻ҙ͢Δ 

    $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ NVMUJNPEVMF
  136. X © DMM.com  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  *OKFDUPSΛ༻ҙ͢Δ 

    $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ NVMUJNPEVMF
  137. X © DMM.com ᶃ.PEVMFΛ༻ҙ͢Δ @Module internal abstract class CounterModule {

    @Singleton @Binds abstract fun provideCounter(impl: CounterImpl): Counter } @Module internal abstract class GreetingModule { @Binds abstract fun provideGreeter(impl: GreeterImpl): Greeter }
  138. X © DMM.com  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  *OKFDUPSΛ༻ҙ͢Δ 

    $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ NVMUJNPEVMF
  139. X © DMM.com  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  *OKFDUPSΛ༻ҙ͢Δ 

    $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ NVMUJNPEVMF
  140. X © DMM.com ᶄ'SBHNFOU.PEVMFΛ༻ҙ͢Δ @Module internal abstract class GreetingFragmentModule {

    @ContributesAndroidInjector abstract fun greetingFragment(): GreetingFragment } @Module internal abstract class CounterFragmentModule { @ContributesAndroidInjector abstract fun counterFragment(): CounterFragment }
  141. X © DMM.com  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  *OKFDUPSΛ༻ҙ͢Δ 

    $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ NVMUJNPEVMF
  142. X © DMM.com  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  *OKFDUPSΛ༻ҙ͢Δ 

    $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ NVMUJNPEVMF
  143. X © DMM.com ᶅ*OKFDUPSΛ༻ҙ͢Δ class CounterInjector : HasDispatchingInjector<Fragment> { @Inject

    lateinit var supportFragmentInjector: DispatchingAndroidInjector<Fragment> override fun dispatchingAndroidInjector(): DispatchingAndroidInjector<Fragment> = supportFragmentInjector } class GreetingInjector : HasDispatchingInjector<Fragment> { @Inject lateinit var supportFragmentInjector: DispatchingAndroidInjector<Fragment> override fun dispatchingAndroidInjector(): DispatchingAndroidInjector<Fragment> = supportFragmentInjector }
  144. X © DMM.com  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  *OKFDUPSΛ༻ҙ͢Δ 

    $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ NVMUJNPEVMF
  145. X © DMM.com  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  *OKFDUPSΛ༻ҙ͢Δ 

    $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ NVMUJNPEVMF
  146. X © DMM.com ᶆ$PNQPOFOUΛ༻ҙ͢Δ @Singleton @Component( modules = [ AndroidInjectionModule::class,

    CounterModule::class, CounterFragmentModule::class]) interface CounterComponent : AndroidInjector<CounterInjector> @Singleton @Component( modules = [ AndroidInjectionModule::class, GreetingModule::class, GreetingFragmentModule::class]) interface GreetingComponent : AndroidInjector<GreetingInjector>
  147. X © DMM.com  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  *OKFDUPSΛ༻ҙ͢Δ 

    $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ NVMUJNPEVMF
  148. X © DMM.com  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  *OKFDUPSΛ༻ҙ͢Δ 

    $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ NVMUJNPEVMF
  149. X © DMM.com ᶇ"QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ͢Δ class Application : android.app.Application(), HasSupportFragmentInjector {

    private val fragmentInjector = ModuleInjector<Fragment>() override fun supportFragmentInjector(): AndroidInjector<Fragment> = fragmentInjector override fun onCreate() { super.onCreate() val counterInjector = CounterInjector() DaggerCounterComponent.create().inject(counterInjector) val greetingInjector = GreetingInjector() DaggerGreetingComponent.create().inject(greetingInjector) fragmentInjector.addInjector(counterInjector) fragmentInjector.addInjector(greetingInjector) } }
  150. X © DMM.com class Application : android.app.Application(), HasSupportFragmentInjector { private

    val fragmentInjector = ModuleInjector<Fragment>() override fun supportFragmentInjector(): AndroidInjector<Fragment> = fragmentInjector override fun onCreate() { super.onCreate() val counterInjector = CounterInjector() DaggerCounterComponent.create().inject(counterInjector) val greetingInjector = GreetingInjector() DaggerGreetingComponent.create().inject(greetingInjector) fragmentInjector.addInjector(counterInjector) fragmentInjector.addInjector(greetingInjector) } } ᶇ"QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ͢Δ
  151. X © DMM.com class Application : android.app.Application(), HasSupportFragmentInjector { private

    val fragmentInjector = ModuleInjector<Fragment>() override fun supportFragmentInjector(): AndroidInjector<Fragment> = fragmentInjector override fun onCreate() { super.onCreate() val counterInjector = CounterInjector() DaggerCounterComponent.create().inject(counterInjector) val greetingInjector = GreetingInjector() DaggerGreetingComponent.create().inject(greetingInjector) fragmentInjector.addInjector(counterInjector) fragmentInjector.addInjector(greetingInjector) } } ᶇ"QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ͢Δ
  152. X © DMM.com class Application : android.app.Application(), HasSupportFragmentInjector { private

    val fragmentInjector = ModuleInjector<Fragment>() override fun supportFragmentInjector(): AndroidInjector<Fragment> = fragmentInjector override fun onCreate() { super.onCreate() val counterInjector = CounterInjector() DaggerCounterComponent.create().inject(counterInjector) val greetingInjector = GreetingInjector() DaggerGreetingComponent.create().inject(greetingInjector) fragmentInjector.addInjector(counterInjector) fragmentInjector.addInjector(greetingInjector) } } ᶇ"QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ͢Δ
  153. X © DMM.com class Application : android.app.Application(), HasSupportFragmentInjector { private

    val fragmentInjector = ModuleInjector<Fragment>() override fun supportFragmentInjector(): AndroidInjector<Fragment> = fragmentInjector override fun onCreate() { super.onCreate() val counterInjector = CounterInjector() DaggerCounterComponent.create().inject(counterInjector) val greetingInjector = GreetingInjector() DaggerGreetingComponent.create().inject(greetingInjector) fragmentInjector.addInjector(counterInjector) fragmentInjector.addInjector(greetingInjector) } } ᶇ"QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ͢Δ
  154. X © DMM.com  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  *OKFDUPSΛ༻ҙ͢Δ 

    $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ NVMUJNPEVMF
  155. X © DMM.com  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  *OKFDUPSΛ༻ҙ͢Δ 

    $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ NVMUJNPEVMF
  156. X © DMM.com ᶈ֤ॴͰ*OKFDU class CounterFragment : Fragment() { @Inject

    lateinit var counter: Counter override fun onAttach(context: Context?) { AndroidSupportInjection.inject(this) super.onAttach(context) } … } class GreetingFragment : Fragment() { @Inject lateinit var greeter: Greeter override fun onAttach(context: Context?) { AndroidSupportInjection.inject(this) super.onAttach(context) } … }
  157. X © DMM.com ྲྀΕ

  158. X © DMM.com ྲྀΕ

  159. X © DMM.com ྲྀΕ class Application : …, HasSupportFragmentInjector {

    private val moduleFragmentInjector … }
  160. X © DMM.com ྲྀΕ class Application : …, HasSupportFragmentInjector {

    private val moduleFragmentInjector … }
  161. X © DMM.com ྲྀΕ class Application : …, HasSupportFragmentInjector {

    private val moduleFragmentInjector … }
  162. X © DMM.com ྲྀΕ class Application : …, HasSupportFragmentInjector {

    private val moduleFragmentInjector … } class CounterFragment : Fragment() { ɹɹ… AndroidSupportInjection.inject(this) … }
  163. X © DMM.com ྲྀΕ class Application : …, HasSupportFragmentInjector {

    private val moduleFragmentInjector … } class CounterFragment : Fragment() { ɹɹ… AndroidSupportInjection.inject(this) … } class MainActivity : AppCompatActivity() { … } HasSupportFragmentInjectorΛ࣮૷ͯ͠Δ͔ʁ
  164. X © DMM.com ྲྀΕ class Application : …, HasSupportFragmentInjector {

    private val moduleFragmentInjector … } class CounterFragment : Fragment() { ɹɹ… AndroidSupportInjection.inject(this) … } class MainActivity : AppCompatActivity() { … } HasSupportFragmentInjectorΛ࣮૷ͯ͠Δ͔ʁ
  165. X © DMM.com ྲྀΕ class Application : …, HasSupportFragmentInjector {

    private val moduleFragmentInjector … } class CounterFragment : Fragment() { ɹɹ… AndroidSupportInjection.inject(this) … } class MainActivity : AppCompatActivity() { … } HasSupportFragmentInjectorΛ࣮૷ͯ͠Δ͔ʁ
  166. X © DMM.com ྲྀΕ class Application : …, HasSupportFragmentInjector {

    private val moduleFragmentInjector … } class CounterFragment : Fragment() { ɹɹ… AndroidSupportInjection.inject(this) … } class MainActivity : AppCompatActivity() { … } HasSupportFragmentInjectorΛ࣮૷ͯ͠Δ͔ʁ
  167. X © DMM.com %ZOBNJD'FBUVSF.PEVMF

  168. X © DMM.com %ZOBNJD'FBUVSF.PEVMF͕͋Δ࣌ͷ%* BQQ DPVOUFS HSFFUJOH ͍··Ͱ

  169. X © DMM.com %ZOBNJD'FBUVSF.PEVMF͕͋Δ࣌ͷ%* BQQ DPVOUFS HSFFUJOH HSFFUJOHΛEZOBNJDGFBUVSFʹ BQQ DPVOUFS

    HSFFUJOH ͍··Ͱ
  170. X © DMM.com %ZOBNJD'FBUVSF.PEVMF͕͋Δ࣌ͷ%* BQQ DPVOUFS HSFFUJOH HSFFUJOHΛEZOBNJDGFBUVSFʹ BQQ DPVOUFS

    HSFFUJOH ͍··Ͱ
  171. X © DMM.com  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  *OKFDUPSΛ༻ҙ͢Δ 

    $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ NVMUJNPEVMF
  172. X © DMM.com  .PEVMFΛ༻ҙ͢Δ  'SBHNFOU.PEVMFΛ༻ҙ͢Δ  *OKFDUPSΛ༻ҙ͢Δ 

    $PNQPOFOUΛ༻ҙ͢Δ  "QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ  ֤ॴͰJOKFDU ࠓ·Ͱͱಉ͡खॱͰɺEBHHFSBOESPJEΛ࢖࣮ͬͯ૷ͯ͠ΈΔ EBHHFSBOESPJEͰ%FQFOEFODZ*OKFDUJPO͢Δ NVMUJNPEVMF
  173. X © DMM.com ᶇ"QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ͢Δ class Application : android.app.Application(), HasSupportFragmentInjector {

    private val fragmentInjector = ModuleInjector<Fragment>() override fun supportFragmentInjector(): AndroidInjector<Fragment> = fragmentInjector override fun onCreate() { super.onCreate() val counterInjector = CounterInjector() DaggerCounterComponent.create().inject(counterInjector) val greetingInjector = GreetingInjector() DaggerGreetingComponent.create().inject(greetingInjector) fragmentInjector.addInjector(counterInjector) fragmentInjector.addInjector(greetingInjector) } }
  174. X © DMM.com ᶇ"QQMJDBUJPOPO$SFBUFͰ$PNQPOFOUΛॳظԽ͢Δ class Application : android.app.Application(), HasSupportFragmentInjector {

    private val fragmentInjector = ModuleInjector<Fragment>() override fun supportFragmentInjector(): AndroidInjector<Fragment> = fragmentInjector override fun onCreate() { super.onCreate() val counterInjector = CounterInjector() DaggerCounterComponent.create().inject(counterInjector) val greetingInjector = GreetingInjector() DaggerGreetingComponent.create().inject(greetingInjector) fragmentInjector.addInjector(counterInjector) fragmentInjector.addInjector(greetingInjector) } }
  175. X © DMM.com "QQMJDBUJPOPO$SFBUFҎ߱ͷద੾ͳλΠϛϯάͰ JOKFDUPSΛੜ੒ͯ͠ɺNPEVMF*OKFDUPSʹ௥Ճ͢Δ ղܾࡦͷҰͭ

  176. X © DMM.com "QQMJDBUJPOPO$SFBUFҎ߱ͷద੾ͳλΠϛϯάͰ JOKFDUPSΛੜ੒ͯ͠ɺNPEVMF*OKFDUPSʹ௥Ճ͢Δ ղܾࡦͷҰͭ

  177. X © DMM.com ͨͱ͑͹ɺ͜Μͳؔ਺Λ࡞Δ object GreetingInjection { fun inject(fragment: Fragment)

    { val application = fragment.requireActivity().application as Application if (application.moduleFragmentInjector.injectors().all { it !is GreetingInjector }) { val injector = GreetingInjector() val component = DaggerGreetingComponent.builder() .counter(application.counterComponent().counter()) .build() component.inject(injector) application.addFragmentInjector(injector) } AndroidSupportInjection.inject(fragment) } }
  178. X © DMM.com ͨͱ͑͹ɺ͜Μͳؔ਺Λ࡞Δ object GreetingInjection { fun inject(fragment: Fragment)

    { val application = fragment.requireActivity().application as Application if (application.moduleFragmentInjector.injectors().all { it !is GreetingInjector }) { val injector = GreetingInjector() val component = DaggerGreetingComponent.builder() .counter(application.counterComponent().counter()) .build() component.inject(injector) application.addFragmentInjector(injector) } AndroidSupportInjection.inject(fragment) } }
  179. X © DMM.com ͨͱ͑͹ɺ͜Μͳؔ਺Λ࡞Δ object GreetingInjection { fun inject(fragment: Fragment)

    { val application = fragment.requireActivity().application as Application if (application.moduleFragmentInjector.injectors().all { it !is GreetingInjector }) { val injector = GreetingInjector() val component = DaggerGreetingComponent.builder() .counter(application.counterComponent().counter()) .build() component.inject(injector) application.addFragmentInjector(injector) } AndroidSupportInjection.inject(fragment) } }
  180. X © DMM.com ͨͱ͑͹ɺ͜Μͳؔ਺Λ࡞Δ object GreetingInjection { fun inject(fragment: Fragment)

    { val application = fragment.requireActivity().application as Application if (application.moduleFragmentInjector.injectors().all { it !is GreetingInjector }) { val injector = GreetingInjector() val component = DaggerGreetingComponent.builder() .counter(application.counterComponent().counter()) .build() component.inject(injector) application.addFragmentInjector(injector) } AndroidSupportInjection.inject(fragment) } }
  181. X © DMM.com ͨͱ͑͹ɺ͜Μͳؔ਺Λ࡞Δ object GreetingInjection { fun inject(fragment: Fragment)

    { val application = fragment.requireActivity().application as Application if (application.moduleFragmentInjector.injectors().all { it !is GreetingInjector }) { val injector = GreetingInjector() val component = DaggerGreetingComponent.builder() .counter(application.counterComponent().counter()) .build() component.inject(injector) application.addFragmentInjector(injector) } AndroidSupportInjection.inject(fragment) } } "DUJWJUZʹNPEVMF*OKFDUPS͕͋Δ৔߹Λߟྀͯ͠ɺ "OESPJE4VQQPSU*OKFDUJPOͱಉ͡Α͏ͳ࣮૷ʹ͢Δͷ΋Մ
  182. X © DMM.com ͨͱ͑͹ɺ͜Μͳؔ਺Λ࡞Δ object GreetingInjection { fun inject(fragment: Fragment)

    { val application = fragment.requireActivity().application as Application if (application.moduleFragmentInjector.injectors().all { it !is GreetingInjector }) { val injector = GreetingInjector() val component = DaggerGreetingComponent.builder() .counter(application.counterComponent().counter()) .build() component.inject(injector) application.addFragmentInjector(injector) } AndroidSupportInjection.inject(fragment) } } ˞"DUJWJUZͰ*OKFDUPSΛ࣋ͭͱ͖͸͜ͷํ๏ͩͱ͏·͍͔͘ͳ͍ͷͰ ৚݅෼ذ͢Δඞཁ͕͋Γ·͢ʂ
  183. X © DMM.com ͦ͏͢ΔͱɺJOKFDUઌ͸͜ͷมߋ͚ͩͰࠓ·Ͱ௨Γಈ͘Α͏ʹͳΔ class GreetingFragment : Fragment() { @Inject

    lateinit var greeter: Greeter override fun onAttach(context: Context?) { GreetingInjection.inject(this) super.onAttach(context) } … } class GreetingFragment : Fragment() { @Inject lateinit var greeter: Greeter override fun onAttach(context: Context?) { AndroidSupportInjection.inject(this) super.onAttach(context) } … }
  184. X © DMM.com ͦ͏͢ΔͱɺJOKFDUઌ͸͜ͷมߋ͚ͩͰࠓ·Ͱ௨Γಈ͘Α͏ʹͳΔ class GreetingFragment : Fragment() { @Inject

    lateinit var greeter: Greeter override fun onAttach(context: Context?) { GreetingInjection.inject(this) super.onAttach(context) } … } class GreetingFragment : Fragment() { @Inject lateinit var greeter: Greeter override fun onAttach(context: Context?) { AndroidSupportInjection.inject(this) super.onAttach(context) } … }
  185. X © DMM.com ࿩ͨ͜͠ͱৼΓฦΓ

  186. X © DMM.com ࿩ͨ͜͠ͱৼΓฦΓ w %FQFOEFODZ*OKFDUJPOͱ͸ w %BHHFSͷ࢖͍ํͷҰྫɺखॱɺ࢓૊Έ w %BHHFS"OESPJEαϙʔτͷ࢖͍ํͷҰྫɺखॱɺ࢓૊Έ

    w ͦͷ··Ͱ͸ϚϧνϞδϡʔϧରԠͰ͖ͳ͍έʔε͕͋Δ͜ͱ w .PEVMF*OKFDUPSΛಋೖ͢Δ͜ͱͰରԠͰ͖Δ͜ͱ w %ZOBNJD'FBUVSF.PEVMF࣌͸ɺద੾ͳλΠϛϯάͰ*OKFDUPSΛ .PEVMF*OKFDUPSʹࠩ͠ࠐΜͰ͋͛Δඞཁ͕͋Δ͜ͱ
  187. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠