koin: Injecting the interface in constructor of viewModel - devrath/DroidDi GitHub Wiki
Interface as Service
interface HelloService {
fun doSomething(): String
}
Implementation of Service
class HelloServiceImpl : HelloService {
override fun doSomething(): String {
return "Hello Service, Koin!"
}
}
Kotlin Module
val viewModelModules = module {
viewModel { VariableInjectionVm(get()) }
}
ViewModel
class VariableInjectionVm(
private val helloService: HelloService
) : ViewModel() {
fun demo(): String {
return helloService.doSomething()
}
}