Skip to content

Commit

Permalink
Merge pull request #1909 from igorwojda/patch-2
Browse files Browse the repository at this point in the history
Add testing description for Context Isolation
  • Loading branch information
arnaudgiuliani authored Sep 17, 2024
2 parents 48c52a2 + 8de1180 commit faecabe
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/reference/koin-core/context-isolation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: Context Isolation
---

## What Context Isolation?

For SDK Makers, you can also work with Koin in a non-global way: use Koin for the DI of your library and avoid any conflict by people using your library and Koin by isolating your context.

Expand Down Expand Up @@ -53,3 +54,24 @@ class MyKoinComponent : IsolatedKoinComponent(){
// inject & get will target MyKoinContext
}
```

## Testing

To test classes that are retrieving dependencies with `by inject()` delegate override `getKoin()` method and define custom Koin module:

```kotlin
class MyClassTest : KoinTest {
// Koin Context used to retrieve dependencies
override fun getKoin(): Koin = MyIsolatedKoinContext.koin

@Before
fun setUp() {
// Define custom Koin module
val module = module {
// Register dependencies
}

koin.loadModules(listOf(module))
}
}
```

0 comments on commit faecabe

Please sign in to comment.