I am refactoring applications that pass "application context" to the view model factory and is accessed in the view model. Is there a definitive opinion if this coding practice is good/ bad/ or OK? For example, I use it to call data repository that loads a data file from the assets directory. If there is a "better practice", where is it documented?
Code snippets
class MainViewModelFactory(private val applicationContext: Context) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(MainViewModel::class.java)) {
return MainViewModel(applicationContext) as T
....
class MainViewModel(
applicationContext: Context
) : ViewModel() {....
init {
_dataIsLoaded.value = dataRepository.myFunction(applicationContext, Constants.data_file_name)