Skip to content

Commit

Permalink
Merge tag '4.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgiuliani committed Jan 7, 2025
2 parents 3b6a84a + a3f80f2 commit 32c43ac
Show file tree
Hide file tree
Showing 84 changed files with 4,151 additions and 293 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/checkout@v3

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v3

- name: Set up JDK
uses: actions/setup-java@v3
Expand Down
71 changes: 33 additions & 38 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,37 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'java' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

language: [ 'java-kotlin' ]
steps:
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

- name: Build and install all
# working-directory: core
run: cd projects && ./install.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

- name: Build and install all
# working-directory: core
run: cd projects && ./install.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: actions/checkout@v3

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v3

- name: Set up JDK
uses: actions/setup-java@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/checkout@v3

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v3

- name: Set up JDK
uses: actions/setup-java@v3
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
uses: actions/checkout@v3

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v3

- name: Set up JDK
uses: actions/setup-java@v3
Expand All @@ -29,7 +29,7 @@ jobs:
- name: Install
run: cd projects && ./install.sh

- name: Test Examples
run: cd examples/jvm-perfs && ./benchmark.sh
- name: Benchmark
run: cd projects && ./benchmark.sh


2 changes: 1 addition & 1 deletion docs/quickstart/android-annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class AppModule
```

* We use the `@Module` to declare our class as Koin module
* The `@ComponentScan("org.koin.sample")` allow to scann any Koin definition in `"org.koin.sample"`package
* The `@ComponentScan("org.koin.sample")` allow to scan any Koin definition in `"org.koin.sample"`package

Let's simply add `@Single` on `UserRepositoryImpl` class to declare it as singleton:

Expand Down
37 changes: 27 additions & 10 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() {
class MainApplication : Application(),KoinStartup {

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.
`KoinStartup` avoid blocking main thread at for startup time, and offers better performances.
:::

## 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)
}

}
```
44 changes: 37 additions & 7 deletions docs/reference/koin-compose/compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@ for an Android/Multiplatform app, use the following packages:
The function `KoinApplication` helps to create Koin application instance, as a Composable:

```kotlin
fun koinConfiguration() = koinApplication {
// your configuration & modules here
modules(...)
}

@Composable
fun App() {
KoinApplication(::koinConfiguration) {
KoinApplication(application = {
modules(...)
}) {

// your screens here ...
MyScreen()
Expand Down Expand Up @@ -160,11 +157,44 @@ fun App(vm : MyViewModel = koinViewModel()) {
}
```

:::warning
:::note
Lazy API are not supported with updates of jetpack Compose
:::

### ViewModel and SavedStateHandle for @Composable

You can have a `SavedStateHandle` constructor parameter, it will be injected regarding the Compose environment (Navigation BackStack or ViewModel).
Either it's injected via ViewModel `CreationExtras` either via Navigation `BackStackEntry`:

```kotlin
// Setting objectId argument in Navhost
NavHost(
navController,
startDestination = "list"
) {
composable("list") { backStackEntry ->
//...
}
composable("detail/{objectId}") { backStackEntry ->
val objectId = backStackEntry.arguments?.getString("objectId")?.toInt()
DetailScreen(navController, objectId!!)
}
}

// Injected Argument in ViewModel
class DetailViewModel(
private val savedStateHandle: SavedStateHandle
) : ViewModel() {

init {
println("$this - objectId: ${savedStateHandle.get<String>("objectId")}")
}
}
```

:::note
More details about SavedStateHandle injection difference: https://github.com/InsertKoinIO/koin/issues/1935#issuecomment-2362335705
:::

## Module loading & unloading tied to Composable

Expand Down
11 changes: 11 additions & 0 deletions docs/reference/koin-core/definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ val presenter : Presenter by inject { parametersOf(view) }

Further reading in the [Injection Parameters Section](/docs/reference/koin-core/injection-parameters)

## Definition Termination - OnClose

You can use the `onClose` function, to add on a definition, the callback once definition closing is called:

```kotlin
class Presenter(val view : View)

val myModule = module {
factory { (view : View) -> Presenter(view) } onClose { // closing callback - it is Presenter }
}
```

## Using definition flags

Expand Down
17 changes: 17 additions & 0 deletions docs/reference/koin-core/lazy-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,21 @@ koin.runOnKoinStarted { koin ->

:::info
Default dispatcher for coroutines engine is `Dispatchers.Default`
:::

### Limitation - Mixing Modules/Lazy Modules

For now we advise to avoid mixing modules & lazy modules, in the startup. Avoid having `mainModule` requiring dependency in `lazyReporter`.

```kotlin
startKoin {
androidLogger()
androidContext(this@TestApp)
modules(mainModule)
lazyModules(lazyReporter)
}
```

:::warning
For now Koin doesn't check if your module depends on a lazy modules
:::
3 changes: 3 additions & 0 deletions docs/reference/koin-core/scopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ From a `Koin` instance, you can access:
- `getScope(id : ScopeID)` - retrieve a previously created scope with given id
- `getOrCreateScope(id : ScopeID, scopeName : Qualifier)` - create or retrieve if already created, the closed scope instance with given id and scopeName

:::note
By default calling `createScope` on an object, doesn't pass the "source" of the scope. You need to pass it as parameters: `T.createScope(<source>)`
:::

### Scope Component: Associate a scope to a component [2.2.0]

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/koin-ktor/ktor.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fun Application.main() {

### Resolve from Ktor Request Scope (since 3.5.0)

You can declare components to live within Ktor request scope timeline. For this, you just need to declare your component inside a `scope<ScopeRequest>` section. Given a `ScopeComponent` class to instantiate on RequestScope, let's declare it:
You can declare components to live within Ktor request scope timeline. For this, you just need to declare your component inside a `scope<RequestScope>` section. Given a `ScopeComponent` class to instantiate on `RequestScope`, let's declare it:

```kotlin
scope<RequestScope>{
Expand Down
Loading

0 comments on commit 32c43ac

Please sign in to comment.