Issue #359
app/build.gradle
implementation "org.koin:koin-core:$Version.koin"
implementation "org.koin:koin-androidx-scope:$Version.koin"
implementation "org.koin:koin-androidx-viewmodel:$Version.koin"
MyApplication.kt
import android.app.Application
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.context.startKoin
import org.koin.dsl.module
class MyApplication: Application() {
var appModule = module {
single { MyRepo() }
viewModel { MyViewModel(get()) }
}
override fun onCreate() {
super.onCreate()
startKoin {
androidLogger()
androidContext(this@MyApplication)
modules(appModule)
}
}
}
MyFragment.kt
import org.koin.androidx.viewmodel.ext.android.viewModel
val viewModel: MyViewModel by viewModel()