koin尚未在多模块项目中启动

pes8fvy9  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(229)

我正在使用koin注入一些类。
我遵循koin官方文件,但每当我启动应用程序时,它就会崩溃。我的项目是一个多模块项目,但我的所有注入都在同一个模块中使用。
my koin模块的定义:

val databaseModule = module {
    factory { provideIoDispatcher() }
    single { provideHerowDatabase(get()) }
    single { provideZoneDAO(get()) }
    single { providePoiDAO(get()) }
    single { provideCampaignDAO(get()) }
    single { provideZoneRepository(get()) }
    single { providePoiRepository(get()) }
    single { provideCampaignRepository(get()) }
}

private fun provideIoDispatcher(): CoroutineDispatcher = Dispatchers.IO

/**and so on**/

应用程序类别:

class DetectionApplication : Application(), Configuration.Provider {

    override fun getWorkManagerConfiguration(): Configuration = Configuration.Builder()
        .setMinimumLoggingLevel(android.util.Log.INFO)
        .build()

    override fun onCreate() {
        super.onCreate()

        startKoin {
            androidLogger()
            androidContext(this@DetectionApplication)
            modules(listOf(databaseModule))
        }
    }
}

清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="io.herow.sdk.detection">

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

    <application android:name=".DetectionApplication">

        <receiver android:name=".location.LocationReceiver" />
        <receiver android:name=".geofencing.GeofencingReceiver" />
        <receiver android:name=".notification.NotificationReceiver" />

        <service
            android:name="androidx.work.impl.foreground.SystemForegroundService"
            android:foregroundServiceType="location"
            tools:node="merge" />

        <provider
            android:name="androidx.work.impl.WorkManagerInitializer"
            android:authorities="${applicationId}.workmanager-init"
            tools:node="merge" />
    </application>
</manifest>

我的项目的入口点

class HerowInitializer private constructor(val context: Context) : KoinComponent {

    //Koin
    private val ioDispatcher: CoroutineDispatcher by inject()

    init {
        loadIdentifiers(context)
    }

    private fun loadIdentifiers(context: Context) {
        CoroutineScope(ioDispatcher).launch {

            /**code**/
        }
    }

错误:

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题