client = DaggerClientComponent.create().client()
"🟢 ${client.fetchData()}"
@Component(modules = [ConnectionModule::class])
interface ClientComponent{
fun client(): Client
}
@Module
interface ConnectionModule {
@Binds
fun bindConnection(networkConnection: NetworkConnection): Connection
}
interface Connection {
fun doReq(): String
}
class NetworkConnection @Inject constructor() : Connection {
val endpoint = if (BuildConfig.DEBUG) {
"DEBUG/endpoint"
} else {
"PROD/endpoint"
}
override fun doReq() = endpoint
}
class Client @Inject constructor(
private val connection: Connection
) {
fun fetchData() = connection.doReq()
}