Hey i am using koin v2.2.2 in my project. In viewm...
# koin
v
Hey i am using koin v2.2.2 in my project. In viewmodel parameter i am declare context object , it giving warning. How to prevent this
Copy code
class XYZViewModel(val context: Context) : BaseViewModel()
Copy code
val xyzModule = module {
   viewModel { XYZViewModel(get()) }
}
r
not a good idea to inject that. Can I ask what you need it for?
v
i need context in my view model
r
“i need context in my view model” - I am asking why
v
to use getString,getDrawable etc. type of function call
r
“If the 
ViewModel
 needs the 
Application
 context, for example to find a system service, it can extend the 
AndroidViewModel
 class and have a constructor that receives the 
Application
 in the constructor, since 
Application
 class extends 
Context
.”
also, it should be available in your koin config file:
Copy code
single { PermissionUtils(androidContext()) }
this is a line from mine
v
okkk got it
r
Copy code
class PermissionUtils(private val context: Context) {
v
thanks a million 👍