-
-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Doc update for Compose features - KoinContext KoinAndroidContext and …
…KoinIsolatedContext
- Loading branch information
1 parent
deb1253
commit 11397b2
Showing
3 changed files
with
140 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: Isolated Context with Compose | ||
--- | ||
|
||
With a Compose application, you can work the same way with an [isolated context](../koin-core/context-isolation.md) to deal with SDK or white label application, in order to not mix your Koin definitions with a end user's one. | ||
|
||
## Define isolated context | ||
|
||
First let's declare our isolated context holder, in order to store our isolated Koin isntance in memory. This can be done with a simple Object class like this. The `MyIsolatedKoinContext` class is holding our Koin instance: | ||
|
||
```kotlin | ||
object MyIsolatedKoinContext { | ||
|
||
val koinApp = koinApplication { | ||
// declare used modules | ||
modules(sdkAppModule) | ||
} | ||
} | ||
``` | ||
|
||
:::note | ||
Adapt the `MyIsolatedKoinContext` class according your need of initialization | ||
::: | ||
|
||
## Setup isolated context with Compose | ||
|
||
Now that you have defined an isolated Koin context, we can setup it up to Compose to use it and override all the API. Just use the `KoinIsolatedContext` at the root Compose function. This will propagate your Koin context in all child composables. | ||
|
||
```kotlin | ||
@Composable | ||
fun App() { | ||
// Set current Koin instance to Compose context | ||
KoinIsolatedContext(context = MyIsolatedKoinContext.koinApp) { | ||
|
||
MyScreen() | ||
} | ||
} | ||
``` | ||
|
||
:::info | ||
All Koin Compose APIs will use your Koi isolated context after the use of `KoinIsolatedContext` | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters