Koin: how to inject data class by koin

Created on 2 Nov 2018  路  3Comments  路  Source: InsertKoinIO/koin

i'm a new in Koin Dependency Injection.i have a problem by data class inject.

data class:

data class CoroutinesDispatcherProvider( val main: CoroutineDispatcher, val computation: CoroutineDispatcher, val io: CoroutineDispatcher )

and viewModel need this data class:

class MyViewModel(private val dispatcherProvider: CoroutinesDispatcherProvider):ViewModel() { }

and finally module is:

val appModule = module { single { (main: CoroutineDispatcher, computation: CoroutineDispatcher, io: CoroutineDispatcher) -> CoroutinesDispatcherProvider( main, computation, io ) } viewModel { MyViewModel(get()) } }

but get error:

` Caused by: org.koin.error.BeanInstanceCreationException: Can't create definition for 'Factory [name='MyViewModel',class='com.example.myapplication.MyViewModel', binds~(androidx.lifecycle.ViewModel)]' due to error :
        Can't create definition for 'Single [name='CoroutinesDispatcherProvider',class='com.example.myapplication.CoroutinesDispatcherProvider']' due to error :
        Can't get parameter value #0 from org.koin.core.parameter.ParameterList@f87fb6

`
what is wrong by appModule?!

question

Most helpful comment

can you just make a small project example and share it?

All 3 comments

seems to be a problem with your injection params.

can you just make a small project example and share it?

Reopen it if needed. Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jeevuz picture Jeevuz  路  4Comments

ILAgent picture ILAgent  路  3Comments

TedHoryczun picture TedHoryczun  路  4Comments

congtuyenvip picture congtuyenvip  路  4Comments

dakuenjery picture dakuenjery  路  4Comments