Upgrade to Pro — share decks privately, control downloads, hide ads and more …

タップルでたっぷりDaggerを使って マルチモジュール構築している話 :)

Sato Shun
September 10, 2019

タップルでたっぷりDaggerを使って マルチモジュール構築している話 :)

タップルでたっぷりDaggerを使ってマルチモジュール構築している話です!

Sato Shun

September 10, 2019
Tweet

More Decks by Sato Shun

Other Decks in Programming

Transcript

  1. CA.apk #8 ࠤ౻ ൏ / Sato Shun Twitter: @stsn_jp GitHub:

    satoshun λοϓϧͰͨͬ΀ΓDaggerΛ࢖ͬͯ ϚϧνϞδϡʔϧߏங͍ͯ͠Δ࿩ :)
  2. Daggerͷجຊߏ੒ • Android Dagger࢖ͬͯ·͢ • ͨͩɺແཧͯ͠࢖͏ඞཁͳ͍ͱࢥ͏:D • Dynamic Feature Moduleͱ૬ੑѱ͍ʢଟ෼ʣ

    • ViewModelͷαϙʔτ͕ೖͬͨΒϫϯͪΌΜ (ISSUE͸͋Δ) • શ෦ɺDagger͔ΒΠϯελϯε࡞Ζ͏ͥʙͬͯײ͡Ͱ͸ͳ ͍ • ࣮͸DaggerΛͨͬ΀Γ࢖ͬͯͳ͍Ͱ͢
  3. AnalyticsModule? • AnalyticsϞδϡʔϧʹఆٛ͞Ε͍ͯΔDaggerͷModule • Google Analytics for Firebaseʹґଘ͍ͯ͠Δ • Google

    Analytics͸ͱͬͬͬͯ΋Ͱ͔͍ϥΠϒϥϦ • Google AnalyticsͷҰ෦ͷػೳ͔͠࢖͍ͬͯͳ͍͠ɺ্ख͍͜ ͱ΍Γ͍ͨ
  4. interface Analytics { ... } . @Singleton internal class FirebaseAnalyticsImpl

    @Inject constructor( private val app: Application ) : Analytics { ... } .
  5. interface Analytics { ... } . @Singleton internal class FirebaseAnalyticsImpl

    @Inject constructor( private val app: Application ) : Analytics { ... } .
  6. interface Analytics { . ... } . @Singleton internal class

    FirebaseAnalyticsImpl @Inject constructor( . private val app: Application ) : Analytics { . ... } .
  7. interface Analytics { . ... . } . @Singleton internal

    class FirebaseAnalyticsImpl @Inject constructor( . private val app: Application ) : Analytics { . ... . } . @Module internal interface AnalyticsBindModule { . @Binds fun bind(impl: FirebaseAnalyticsImpl): Analytics } .
  8. interface Analytics { . ... . } . @Singleton internal

    class FirebaseAnalyticsImpl @Inject constructor( . private val app: Application ) : Analytics { . ... . } . @Module internal interface AnalyticsBindModule { . @Binds fun bind(impl: FirebaseAnalyticsImpl): Analytics } .
  9. interface Analytics { . ... . } . @Singleton .

    internal class FirebaseAnalyticsImpl @Inject constructor( . private val app: Application ) : Analytics { . ... . } . @Module . internal interface AnalyticsBindModule { .. @Binds fun bind(impl: FirebaseAnalyticsImpl): Analytics } ..
  10. @Singleton internal class FirebaseAnalyticsImpl @Inject constructor( . private val app:

    Application ) : Analytics { ... . } . @Module . internal interface AnalyticsBindModule { .. @Binds fun bind(impl: FirebaseAnalyticsImpl): Analytics } .. . @Module(includes = [AnalyticsBindModule::class]) .. object AnalyticsModule { .. ... } .
  11. @Module interface GachaFeatureModule { @ContributesAndroidInjector fun contributeGachaActivity(): GachaActivity } @Module(

    includes = [ GachaFeatureModule::class, SettingFeatureModule::class, ] ) interface FeatureModule
  12. @Module interface GachaFeatureModule { @ContributesAndroidInjector fun contributeGachaActivity(): GachaActivity } @Module(

    includes = [ GachaFeatureModule::class, SettingFeatureModule::class, ShopFeatureModule::class, . ] ) interface FeatureModule
  13. GachaFeatureModule::class, . SettingFeatureModule::class, . ShopFeatureModule::class, . ] . ) .

    interface FeatureModule . @Singleton @Component( modules = [ AndroidInjectionModule::class, FeatureModule::class, AnalyticsModule::class ] ) interface AppComponent : AndroidInjector<App> { ... }
  14. GachaFeatureModule::class, . SettingFeatureModule::class, . ShopFeatureModule::class, . ] . ) .

    interface FeatureModule . @Singleton @Component( modules = [ AndroidInjectionModule::class, FeatureModule::class, AnalyticsModule::class ] ) interface AppComponent : AndroidInjector<App> { ... }
  15. object Activities { /** * AboutActivity */ object About :

    AddressableActivity { override val className = "$PACKAGE_NAME.about.ui.AboutA ctivity" } }
  16. // ͜Ε͸RouterϞδϡʔϧͰఆٛ interface GachaDirections { .. @CheckResult fun createIntent(context: Context):

    Intent } . // ҎԼɺGachaϞδϡʔϧ internal class GachaDirectionsImpl @Inject constructor() : GachaDirections { . override fun createIntent(context: Context): Intent { . return GachaActivity.createIntent(context) } . } .
  17. } . // ҎԼɺGachaϞδϡʔϧ internal class GachaDirectionsImpl @Inject constructor() :

    GachaDirections { . override fun createIntent(context: Context): Intent { . return GachaActivity.createIntent(context) } . } . @Module internal interface GachaBindsModule { . @Binds fun bindGachaDirections(directions: GachaDirectionsImpl): GachaDirections } .
  18. override fun createIntent(context: Context): Intent { . return GachaActivity.createIntent(context) }

    . } . @Module internal interface GachaBindsModule { . @Binds fun bindGachaDirections(directions: GachaDirectionsImpl): GachaDirections } . @Module( includes = [ GachaBindsModule::class ] ) interface GachaFeatureModule