1

Does it violating any conventions? Is it acceptable by MVVM? I have to separate the local data repository and online repository, but for login I have to use multiple repositories for getting response from API and saving credentials if they are correct

I have implemented it just by editing the ViewModelFactory as following

object AppViewModelProvider {
    val Factory = viewModelFactory {
        initializer {
            PostCardsListViewModel(application().container.defaultPosterRepository)
        }
        initializer {
            LoginScreenViewModel(
                application().container.defaultPosterRepository,
                application().container.defaultUserLoginRepository
            )
        }
    }
}

fun CreationExtras.application() =
    (this[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY] as PosterApplication)

I know I can create a domain layer, but this app is as simple as heck, so this case will be the only reason for creating a new layer, but if I want it to be clean I have to refactor the whole project and make use-cases for every usage of repository

1 Answer 1

1

There is no prescribed way to do this. The view model needs what it needs. The important thing to maintain is the contract the view model establishes with the user interface. The public methods of the view model provide a layer of abstraction between the data source and UI, making the number of repositories or services required to get the data irrelevant. The repositories are an implementation detail. Use as many as you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.