I have all of my classes that I would like to inject in a modules
class as such.
class modules {
val myModule = module {
MainActivityViewModel()
single { MyRepo() }
}
}
I have an Application
class that looks like this, which is declared in the manifest.
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
// start Koin!
startKoin {
// declare used Android context
androidContext(this@MyApplication)
// declare modules
modules(listOf(myModule)) <------Here my module is unresolved(AS says unresolved reference)
}
}
}
I am using Koin version 2.1.6
myModule
is defined inside of aclass modules
. You cannot access it without an instance of this class.What most people do is define modules right below the
Application
class declaration as a global variable. You can make itprivate
so it won't be accessible out of the file.Now you can remove
class modules
. But if you really need this class and created it with a purpose you can create an instance of this class and call itsmyModule
variable: