Skip to content

Commit a5f455c

Browse files
reorganise Koin start process
1 parent 79db0fb commit a5f455c

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

app/src/main/java/com/example/nav3recipes/modular/koin/KoinModularActivity.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ import androidx.navigation3.ui.NavDisplay
1010
import com.example.nav3recipes.ui.setEdgeToEdgeConfig
1111
import org.koin.android.ext.android.inject
1212
import org.koin.android.ext.koin.androidContext
13+
import org.koin.android.ext.koin.androidLogger
1314
import org.koin.android.scope.AndroidScopeComponent
1415
import org.koin.androidx.compose.navigation3.getEntryProvider
1516
import org.koin.androidx.scope.activityRetainedScope
17+
import org.koin.androidx.scope.activityScope
1618
import org.koin.core.annotation.KoinExperimentalAPI
19+
import org.koin.core.component.KoinComponent
1720
import org.koin.core.context.startKoin
1821
import org.koin.core.context.stopKoin
22+
import org.koin.core.logger.Level
1923
import org.koin.core.scope.Scope
2024
import org.koin.mp.KoinPlatform
2125

@@ -42,15 +46,7 @@ class KoinModularActivity : ComponentActivity(), AndroidScopeComponent {
4246
override fun onCreate(savedInstanceState: Bundle?) {
4347
super.onCreate(savedInstanceState)
4448

45-
//prevent any already launched Koin instance with other config
46-
if (KoinPlatform.getKoinOrNull() != null) {
47-
stopKoin()
48-
}
49-
// The startKoin block should be placed in Application.onCreate.
50-
startKoin {
51-
androidContext(this@KoinModularActivity)
52-
modules(appModule)
53-
}
49+
initKoin()
5450

5551
setEdgeToEdgeConfig()
5652
setContent {
@@ -64,4 +60,15 @@ class KoinModularActivity : ComponentActivity(), AndroidScopeComponent {
6460
}
6561
}
6662
}
63+
64+
private fun initKoin() {
65+
if (KoinPlatform.getKoinOrNull() == null) {
66+
// The startKoin block should be placed in Application.onCreate.
67+
startKoin {
68+
androidContext(this@KoinModularActivity)
69+
androidLogger(Level.DEBUG)
70+
modules(appModule)
71+
}
72+
}
73+
}
6774
}

0 commit comments

Comments
 (0)