Skip to content

Instantly share code, notes, and snippets.

@markchristopherng
Last active February 24, 2020 22:42
Show Gist options
  • Select an option

  • Save markchristopherng/74bb6a3078d7dabc8125b005b67e8596 to your computer and use it in GitHub Desktop.

Select an option

Save markchristopherng/74bb6a3078d7dabc8125b005b67e8596 to your computer and use it in GitHub Desktop.
@Module
interface DaggerModule {
@Binds
fun provideTimeService(impl: TimeServiceImpl): TimeService
@Binds
fun provideGreetingSersvice(impl: GreetingServiceImpl): GreetingService
}
@Zhuinden
Copy link

Zhuinden commented Feb 20, 2020

@Module
abstract class DaggerModule {
    @Binds
    abstract fun timeService(impl: TimeServiceImpl): TimeService

    @Binds
    abstract fun greetingService(impl: GreetingServiceImpl): GreetingService
}

and

@Singleton class MessageData @Inject constructor() {
}

and

@Singleton class TimeServiceImpl @Inject constructor(): TimeService {
}

and

    class GreetingServiceImpl @Inject constructor(
        private val messageData: MessageData,
        private val timeService: TimeService
    ): GreetingService {
    }

@gildor
Copy link

gildor commented Feb 24, 2020

Also, if replace abstract class with interface it will allow to drop repetitive abstract on methods

@markchristopherng
Copy link
Author

thanks for that, I have updated the example to use an interface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment