Better way of handling direct bindings with kotlin...
# dagger
h
Better way of handling direct bindings with kotlin is to just declare another abstract module which will hold only
@Binds
bindings and then just include it via
submodules
, so you don't have to do
@JvmStatic
nonsense.
s
Yes works better than static methods but it works only with abstract providers right?
How would you convert provideGoogleAnalyticsTracker into a @Binds provider?
Copy code
@Module
internal abstract class AppModule {

    @Module
    companion object {

        @JvmStatic
        @Provides
        @Singleton
        @ApplicationContext
        fun provideApplicationContext( app : Application ) : Context = app.applicationContext

        @JvmStatic
        @Provides
        @Singleton
        fun provideGoogleAnalyticsTracker( @ApplicationContext context : Context ) : Tracker {
            val analytics = GoogleAnalytics.getInstance( context )
            return analytics.newTracker(R.xml.global_tracker)
        }
    }

}
h
Sorry I meant
includes
on a module annotation, not
submodules
s
Did you mean have another abstract module just having @Binds providers and include that?