mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
refactor(di): adopt @KoinApplication with startKoin<T>() compiler plugin API (#5152)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
0f900fe7d7
commit
8e5d99410c
5 changed files with 67 additions and 14 deletions
|
|
@ -37,9 +37,8 @@ import kotlinx.coroutines.withTimeout
|
|||
import org.koin.android.ext.android.get
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.androidx.workmanager.koin.workManagerFactory
|
||||
import org.koin.core.context.startKoin
|
||||
import org.meshtastic.app.di.AppKoinModule
|
||||
import org.meshtastic.app.di.module
|
||||
import org.koin.plugin.module.dsl.startKoin
|
||||
import org.meshtastic.app.di.AndroidKoinApp
|
||||
import org.meshtastic.core.common.ContextServices
|
||||
import org.meshtastic.core.database.DatabaseManager
|
||||
import org.meshtastic.core.repository.MeshPrefs
|
||||
|
|
@ -64,10 +63,9 @@ open class MeshUtilApplication :
|
|||
super.onCreate()
|
||||
ContextServices.app = this
|
||||
|
||||
startKoin {
|
||||
startKoin<AndroidKoinApp> {
|
||||
androidContext(this@MeshUtilApplication)
|
||||
workManagerFactory()
|
||||
modules(AppKoinModule().module())
|
||||
}
|
||||
|
||||
// Schedule periodic MeshLog cleanup
|
||||
|
|
|
|||
26
app/src/main/kotlin/org/meshtastic/app/di/AndroidKoinApp.kt
Normal file
26
app/src/main/kotlin/org/meshtastic/app/di/AndroidKoinApp.kt
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.app.di
|
||||
|
||||
import org.koin.core.annotation.KoinApplication
|
||||
|
||||
/**
|
||||
* Root Koin bootstrap for Android. The K2 compiler plugin uses this to discover the full module graph when
|
||||
* [org.koin.plugin.module.dsl.startKoin] is called with this type parameter.
|
||||
*/
|
||||
@KoinApplication(modules = [AppKoinModule::class])
|
||||
object AndroidKoinApp
|
||||
|
|
@ -25,6 +25,7 @@ import androidx.work.WorkerParameters
|
|||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.HttpClientEngine
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import org.koin.plugin.module.dsl.koinApplication
|
||||
import org.koin.test.verify.definition
|
||||
import org.koin.test.verify.injectedParameters
|
||||
import org.koin.test.verify.verify
|
||||
|
|
@ -60,4 +61,19 @@ class KoinVerificationTest {
|
|||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun verifyTypedBootstrapLoadsModuleGraph() {
|
||||
// koinApplication<T>() is a K2 compiler plugin stub. If the plugin fails to
|
||||
// transform it, the stub throws NotImplementedError at runtime. This test
|
||||
// validates that the production bootstrap path is correctly transformed by
|
||||
// successfully creating and closing the generated Koin application.
|
||||
val app = koinApplication<AndroidKoinApp>()
|
||||
try {
|
||||
// No-op: reaching this point proves the typed bootstrap path did not
|
||||
// throw and the generated application could be created.
|
||||
} finally {
|
||||
app.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue