Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ Create `Module` (recommend to use `object`) and extends from `Leviathan` class

Create fields using these functions:

- Use `by instanceOf(keepAlive){ value }` to create instance dependency
- `keepAlive = true` : instance persists across different scopes
- `keepAlive = false`(default): instance is auto-closed when all scopes close
- Use `by factoryOf(useCache)` to create factory dependency
- `useCache = true` (default): caches instances within the same scope
- `useCache = false`: creates new instance on each access
- Use `by valueOf(value)` to create value dependency (the value may be updated later)
- Use `by providableOf { value }` to create a providable dependency (provider may be updated later)
- Use `by instanceOf { value }` to create a scoped instance dependency
- the instance is shared while it belongs to at least one active scope
- when the last scope closes, the instance is destroyed
- Use `by factoryOf(cacheInScope)` to create factory dependency
- `cacheInScope = true` (default): caches instances within the same scope
- `cacheInScope = false`: creates new instance on each access
- Use `by singleton(value)` to create a constant dependency
- Use `by mutableOf(value)` to create a mutable value dependency
- Use `by mutableOf { value }` to create a mutable provider dependency

All functions return a `Dependency<Type>` instance.

Expand All @@ -71,16 +72,15 @@ Create module

```kotlin
object Module : Leviathan() {
val autoCloseRepository by instanceOf { SampleRepository() }
val keepAliveRepository by instanceOf(keepAlive = true) { SampleRepository() }
val scopedRepository by instanceOf { SampleRepository() }
val repositoryWithParam by factoryOf { SampleRepositoryWithParam(1) }
val repositoryWithDependency by instanceOf {
SampleRepositoryWithDependency(inject(autoCloseRepository))
SampleRepositoryWithDependency(inject(scopedRepository))
}
val interfaceRepo by instanceOf<SampleInterfaceRepo> { SampleInterfaceRepoImpl() }
val constantValue by valueOf(42)
val mutableValue by mutableValueOf(87)
val providable by providableOf { 53 }
val constantValue by singleton(42)
val mutableValue by mutableOf(87)
val mutableProvider by mutableOf { 53 }
}
```

Expand All @@ -89,7 +89,7 @@ Dependencies usage:
```kotlin
// view model
class SomeVM(
dep1: Dependency<SampleRepository> = Module.autoCloseRepository,
dep1: Dependency<SampleRepository> = Module.scopedRepository,
) : ViewModel() {
val dep1value = inject(dep1)

Expand All @@ -101,18 +101,18 @@ class SomeVM(
// compose
@Composable
fun ComposeWithDI() {
val repo1 = inject(Module.autoCloseRepository)
val repo1 = inject(Module.scopedRepository)
val repo2 = inject { Module.repositoryWithParam }
/*..*/
}

// random access
fun foo() {
val scope = DIScope()
val repo1 = Module.autoCloseRepository.injectedIn(scope)
val repo1 = Module.scopedRepository.injectedIn(scope)
// update mutable values
Module.mutableValue.provides(15)
Module.providable.provides { 21 }
Module.mutableProvider.provides { 21 }
/*..*/
scope.close()
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/leviathan.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[versions]
leviathan = "3.3.0"
leviathan = "3.4.0"
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[versions]
agp = "8.13.2"
agp = "9.0.0"
minSdk = "21"
compileSdk = "36"

detekt = "1.23.8"
jetbrains-compose = "1.10.0"
kotlin = "2.3.0"
jetbrains-compose = "1.11.0"
kotlin = "2.3.20"

[libraries]
compose-runtime = { module = "org.jetbrains.compose.runtime:runtime", version.ref = "jetbrains-compose" }
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 10 additions & 21 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion leviathan-compose/api/leviathan-compose.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, wasmJs]
// Targets: [iosArm64, iosSimulatorArm64, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
1 change: 0 additions & 1 deletion leviathan-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ kotlin {
compilerOptions { jvmTarget.set(JvmTarget.JVM_1_8) }

}
iosX64()
iosArm64()
iosSimulatorArm64()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.runComposeUiTest
import androidx.compose.ui.test.v2.runComposeUiTest
import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelStore
Expand All @@ -23,7 +23,7 @@ class LeviathanComposeTest {
class Service

class TestDI : Leviathan() {
val service by instanceOf(keepAlive = false) { Service() }
val service by instanceOf { Service() }
}

class TestVN(testDI: TestDI) : ViewModel() {
Expand Down
12 changes: 7 additions & 5 deletions leviathan/api/jvm/leviathan.api
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ public abstract class com/composegears/leviathan/Leviathan {
protected final fun factoryOf (ZLkotlin/jvm/functions/Function1;)Lcom/composegears/leviathan/Dependency;
public static synthetic fun factoryOf$default (Lcom/composegears/leviathan/Leviathan;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/composegears/leviathan/Dependency;
protected static final fun getValue (Lcom/composegears/leviathan/Dependency;Lcom/composegears/leviathan/Leviathan;Lkotlin/reflect/KProperty;)Lcom/composegears/leviathan/Dependency;
protected final fun instanceOf (ZLkotlin/jvm/functions/Function1;)Lcom/composegears/leviathan/Dependency;
public static synthetic fun instanceOf$default (Lcom/composegears/leviathan/Leviathan;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/composegears/leviathan/Dependency;
protected final fun mutableValueOf (Ljava/lang/Object;)Lcom/composegears/leviathan/MutableDependency;
protected final fun providableOf (Lkotlin/jvm/functions/Function0;)Lcom/composegears/leviathan/MutableDependency;
protected final fun valueOf (Ljava/lang/Object;)Lcom/composegears/leviathan/Dependency;
protected final fun instanceOf (Lkotlin/jvm/functions/Function1;)Lcom/composegears/leviathan/Dependency;
protected final fun mutableOf (Ljava/lang/Object;)Lcom/composegears/leviathan/MutableDependency;
protected final fun mutableOf (Lkotlin/jvm/functions/Function0;)Lcom/composegears/leviathan/MutableDependency;
protected final fun singleton (Ljava/lang/Object;)Lcom/composegears/leviathan/Dependency;
}

public final class com/composegears/leviathan/Leviathan$Companion {
}

public abstract interface annotation class com/composegears/leviathan/LeviathanDslMarker : java/lang/annotation/Annotation {
}

public abstract interface class com/composegears/leviathan/MutableDependency : com/composegears/leviathan/Dependency {
public abstract fun provides (Ljava/lang/Object;)V
}
Expand Down
14 changes: 9 additions & 5 deletions leviathan/api/leviathan.klib.api
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, wasmJs]
// Targets: [iosArm64, iosSimulatorArm64, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
// - Show declarations: true

// Library unique name: <io.github.composegears:leviathan>
open annotation class com.composegears.leviathan/LeviathanDslMarker : kotlin/Annotation { // com.composegears.leviathan/LeviathanDslMarker|null[0]
constructor <init>() // com.composegears.leviathan/LeviathanDslMarker.<init>|<init>(){}[0]
}

abstract interface <#A: kotlin/Any?, #B: kotlin/Any?> com.composegears.leviathan/MutableDependency : com.composegears.leviathan/Dependency<#A> { // com.composegears.leviathan/MutableDependency|null[0]
abstract fun provides(#B) // com.composegears.leviathan/MutableDependency.provides|provides(1:1){}[0]
}
Expand All @@ -18,10 +22,10 @@ abstract class com.composegears.leviathan/Leviathan { // com.composegears.leviat
constructor <init>() // com.composegears.leviathan/Leviathan.<init>|<init>(){}[0]

final fun <#A1: kotlin/Any?> factoryOf(kotlin/Boolean = ..., kotlin/Function1<com.composegears.leviathan/DependencyInitializationScope, #A1>): com.composegears.leviathan/Dependency<#A1> // com.composegears.leviathan/Leviathan.factoryOf|factoryOf(kotlin.Boolean;kotlin.Function1<com.composegears.leviathan.DependencyInitializationScope,0:0>){0§<kotlin.Any?>}[0]
final fun <#A1: kotlin/Any?> instanceOf(kotlin/Boolean = ..., kotlin/Function1<com.composegears.leviathan/DependencyInitializationScope, #A1>): com.composegears.leviathan/Dependency<#A1> // com.composegears.leviathan/Leviathan.instanceOf|instanceOf(kotlin.Boolean;kotlin.Function1<com.composegears.leviathan.DependencyInitializationScope,0:0>){0§<kotlin.Any?>}[0]
final fun <#A1: kotlin/Any?> mutableValueOf(#A1): com.composegears.leviathan/MutableDependency<#A1, #A1> // com.composegears.leviathan/Leviathan.mutableValueOf|mutableValueOf(0:0){0§<kotlin.Any?>}[0]
final fun <#A1: kotlin/Any?> providableOf(kotlin/Function0<#A1>): com.composegears.leviathan/MutableDependency<#A1, kotlin/Function0<#A1>> // com.composegears.leviathan/Leviathan.providableOf|providableOf(kotlin.Function0<0:0>){0§<kotlin.Any?>}[0]
final fun <#A1: kotlin/Any?> valueOf(#A1): com.composegears.leviathan/Dependency<#A1> // com.composegears.leviathan/Leviathan.valueOf|valueOf(0:0){0§<kotlin.Any?>}[0]
final fun <#A1: kotlin/Any?> instanceOf(kotlin/Function1<com.composegears.leviathan/DependencyInitializationScope, #A1>): com.composegears.leviathan/Dependency<#A1> // com.composegears.leviathan/Leviathan.instanceOf|instanceOf(kotlin.Function1<com.composegears.leviathan.DependencyInitializationScope,0:0>){0§<kotlin.Any?>}[0]
final fun <#A1: kotlin/Any?> mutableOf(#A1): com.composegears.leviathan/MutableDependency<#A1, #A1> // com.composegears.leviathan/Leviathan.mutableOf|mutableOf(0:0){0§<kotlin.Any?>}[0]
final fun <#A1: kotlin/Any?> mutableOf(kotlin/Function0<#A1>): com.composegears.leviathan/MutableDependency<#A1, kotlin/Function0<#A1>> // com.composegears.leviathan/Leviathan.mutableOf|mutableOf(kotlin.Function0<0:0>){0§<kotlin.Any?>}[0]
final fun <#A1: kotlin/Any?> singleton(#A1): com.composegears.leviathan/Dependency<#A1> // com.composegears.leviathan/Leviathan.singleton|singleton(0:0){0§<kotlin.Any?>}[0]

final object Companion // com.composegears.leviathan/Leviathan.Companion|null[0]
}
Expand Down
1 change: 0 additions & 1 deletion leviathan/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ kotlin {
minSdk = libs.versions.minSdk.get().toInt()
compilerOptions { jvmTarget.set(JvmTarget.JVM_1_8) }
}
iosX64()
iosArm64()
iosSimulatorArm64()

Expand Down
Loading
Loading