I have ViewModelFactory which requires me to pass ...
# android
a
I have ViewModelFactory which requires me to pass class as a constructor. But currently the class is an interface. May I know how can I achieve this?
Copy code
interface VoteRepository {
    fun getVoteDetails(): MutableLiveData<ArrayList<Vote>>
}

val voteViewModelFactory = VoteViewModelFactory(// I need to pass the VoteRepository here)
google 3
j
You have to create the implementation for VoteRepository
a
@Javier I do have a VoteRepositoryImpl class.
I separate the actual implementation and interface.
j
Then you can pass a VoteRepositoryImpl(), but I think you are using Dagger, Koin or Kodein maybe?
a
Nope. I'm not using any one of them. I am trying to avoid using any dependency.
­čĄö 1
I'm trying clean approach.
j
Then you will have to create your own DI
a
Thank you.
s
Copy code
class MyViewModelFactory : ViewModelProvider.Factory {
    override fun <T : ViewModel?> create(modelClass: Class<T>): T {
        return when {
            modelClass.isAssignableFrom(VoteViewModel::class.java) -> {
                VoteViewModel(
                    VoteRepositoryImpl(
                        MyProvider.apolloClient
                    )
                ) as T
            }
Are You talking about this? @Ayden