I called a ViewModel that gets three arguments in its constructor:
class DetailViewModel(
private val id: Long,
private val tipo: String,
private val msRepository: MSRepository) : ViewModel() {
val establishmentProfessional by lazyDeferred {
msRepository.getEstablishment(id, tipo)
}
}
And I created a factory to build the object com DI:
class DetailViewModelFactory(
private val id: Long,
private val tipo: String,
private val msRepository: MSRepository
) : ViewModelProvider.NewInstanceFactory() {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
return DetailViewModelFactory(id, tipo, msRepository) as T
}
}
I wrote the Factory binding as follows:bind() from factory { id: Long, entity: String -> DetailViewModelFactory(id, entity, instance()) }
, the latter being previously reported.
However, when I try to retrieve the object, I can not spell the code correctly:
private var viewModelFactory: ( (Long, String) -> DetailViewModelFactory) by factory()
How do I retrieve the object correctly with a series of arguments?
I did not find in the documentation how to do it, because the information is insufficient.Retrieval Direct, multiple argumentes, Little documentation on multi-argument factories, How can I use Kodein's direct retrieval to fetch a dependency bound as a factory?