Ink
05/22/2021, 11:38 AMval welcomeModule = module {
single<MyService> { MyServiceImpl() }
}
ViewModel:
class MyViewModel(private val myService: MyService) : ViewModel() {
...
}
@Composable function:
@Composable
fun Screen(){
val myViewModel: MyViewModel= viewModel()
}
I tried:
val myService = get<MyService>()
and put it to viewModel() but it doesn't workTin Tran
05/22/2021, 12:33 PMTin Tran
05/22/2021, 12:33 PMZun
05/22/2021, 12:41 PMAbhishek Dewan
05/22/2021, 3:18 PMviewModel<MyViewModel> { MyViewModel(get()) }
into your welcome module. essentially your missing the binding that tells Koin how to create an instance of MyViewModel.Ink
05/23/2021, 9:50 AMAbhishek Dewan
05/23/2021, 3:11 PMval viewModel: MyViewModel = get()
and be sure to use the get() from koin