Skip to content

Commit

Permalink
doc update
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgiuliani committed Oct 30, 2024
1 parent 8ba50d6 commit 8daec73
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions docs/reference/koin-android/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,16 @@ startKoin {
}
```

## Start Koin with Androidx Startup (4.0)
## Start Koin with Androidx Startup (4.0.1)

By using Gradle packge `koin-androidx-startup`, we can use `onKoinStartup` function durectly in `init` block of your Application class:
By using Gradle packge `koin-androidx-startup`, we can use `KoinStartup` interface to declare your Koin configuration your Application class:

```kotlin
class MainApplication : Application() {

init {
// Use AndroidX Startup for Koin
onKoinStartup {
androidContext(this@MainApplication)
modules(allModules)
}
override fun onKoinStartup(): KoinAppDeclaration = {
androidContext(this@MainApplication)
modules(appModule)
}

override fun onCreate() {
Expand All @@ -96,5 +93,25 @@ class MainApplication : Application() {
This replaces the `startKoin` function that is usally used in `onCreate`.

:::info
Gain over from `onKoinStartup` to regular `startKoin` can go over 30% of time gained, for startup time.
Gain over from `KoinStartup` to regular `startKoin` can go over 30% of time gained, for startup time.
:::

## Startup Dependency with Koin

You can make your `Initializer` depend on `KoinInitializer` if you need Koin to be setup, and allow to inject dependencies:

```kotlin
class CrashTrackerInitializer : Initializer<Unit>, KoinComponent {

private val crashTrackerService: CrashTrackerService by inject()

override fun create(context: Context) {
crashTrackerService.configure(context)
}

override fun dependencies(): List<Class<out Initializer<*>>> {
return listOf(KoinInitializer::class.java)
}

}
```

0 comments on commit 8daec73

Please sign in to comment.