Skip to content

Commit

Permalink
fix: replaced singleton with provider for factory to remove closu…
Browse files Browse the repository at this point in the history
…re caching
  • Loading branch information
y9san9 committed Dec 24, 2023
1 parent 7adfb48 commit ee0c76d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions core/src/commonMain/kotlin/app/meetacy/di/factory/Factory0.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.meetacy.di.factory

import app.meetacy.di.DI
import app.meetacy.di.builder.DIBuilder
import app.meetacy.di.builder.DIBuilderSingletonDelegate
import app.meetacy.di.builder.DIBuilderProviderDelegate
import app.meetacy.di.internal.LazyFactory
import kotlin.reflect.KProperty
import kotlin.reflect.KType
Expand Down Expand Up @@ -49,13 +49,13 @@ public inline fun <reified R> DIBuilder.factory0(
name: String? = null,
crossinline factory: DI.() -> R
) {
singleton(name) {
provider(name) {
Factory0 { factory() }
}
}

public inline fun <reified R> DIBuilder.factory0(
crossinline factory: DI.() -> R
): DIBuilderSingletonDelegate<Factory0<R>> = singleton {
): DIBuilderProviderDelegate<Factory0<R>> = provider {
Factory0 { factory() }
}
6 changes: 3 additions & 3 deletions core/src/commonMain/kotlin/app/meetacy/di/factory/Factory1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.meetacy.di.factory

import app.meetacy.di.DI
import app.meetacy.di.builder.DIBuilder
import app.meetacy.di.builder.DIBuilderSingletonDelegate
import app.meetacy.di.builder.DIBuilderProviderDelegate
import app.meetacy.di.internal.LazyFactory
import kotlin.reflect.KProperty
import kotlin.reflect.KType
Expand Down Expand Up @@ -67,13 +67,13 @@ public inline fun <reified T1, reified R> DIBuilder.factory1(
name: String? = null,
crossinline factory: DI.(arg1: T1) -> R
) {
singleton(name) {
provider(name) {
Factory1 { arg1: T1 -> factory(arg1) }
}
}

public inline fun <reified T1, reified R> DIBuilder.factory1(
crossinline factory: DI.(arg1: T1) -> R
): DIBuilderSingletonDelegate<Factory1<T1, R>> = singleton {
): DIBuilderProviderDelegate<Factory1<T1, R>> = provider {
Factory1 { arg1: T1 -> factory(arg1) }
}
6 changes: 3 additions & 3 deletions core/src/commonMain/kotlin/app/meetacy/di/factory/Factory2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.meetacy.di.factory

import app.meetacy.di.DI
import app.meetacy.di.builder.DIBuilder
import app.meetacy.di.builder.DIBuilderSingletonDelegate
import app.meetacy.di.builder.DIBuilderProviderDelegate
import app.meetacy.di.internal.LazyFactory
import kotlin.reflect.KProperty
import kotlin.reflect.KType
Expand Down Expand Up @@ -74,13 +74,13 @@ public inline fun <reified T1, reified T2, reified R> DIBuilder.factory2(
name: String? = null,
crossinline factory: DI.(arg1: T1, arg2: T2) -> R
) {
singleton(name) {
provider(name) {
Factory2 { arg1: T1, arg2: T2 -> factory(arg1, arg2) }
}
}

public inline fun <reified T1, reified T2, reified R> DIBuilder.factory2(
crossinline factory: DI.(arg1: T1, arg2: T2) -> R
): DIBuilderSingletonDelegate<Factory2<T1, T2, R>> = singleton {
): DIBuilderProviderDelegate<Factory2<T1, T2, R>> = provider {
Factory2 { arg1: T1, arg2: T2 -> factory(arg1, arg2) }
}
6 changes: 3 additions & 3 deletions core/src/commonMain/kotlin/app/meetacy/di/factory/Factory3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.meetacy.di.factory

import app.meetacy.di.DI
import app.meetacy.di.builder.DIBuilder
import app.meetacy.di.builder.DIBuilderSingletonDelegate
import app.meetacy.di.builder.DIBuilderProviderDelegate
import app.meetacy.di.internal.LazyFactory
import kotlin.reflect.KProperty
import kotlin.reflect.KType
Expand Down Expand Up @@ -81,13 +81,13 @@ public inline fun <reified T1, reified T2, reified T3, reified R> DIBuilder.fact
name: String? = null,
crossinline factory: DI.(arg1: T1, arg2: T2, arg3: T3) -> R
) {
singleton(name) {
provider(name) {
Factory3 { arg1: T1, arg2: T2, arg3: T3 -> factory(arg1, arg2, arg3) }
}
}

public inline fun <reified T1, reified T2, reified T3, reified R> DIBuilder.factory3(
crossinline factory: DI.(arg1: T1, arg2: T2, arg3: T3) -> R
): DIBuilderSingletonDelegate<Factory3<T1, T2, T3, R>> = singleton {
): DIBuilderProviderDelegate<Factory3<T1, T2, T3, R>> = provider {
Factory3 { arg1: T1, arg2: T2, arg3: T3 -> factory(arg1, arg2, arg3) }
}
8 changes: 4 additions & 4 deletions core/src/commonMain/kotlin/app/meetacy/di/factory/Factory4.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.meetacy.di.factory

import app.meetacy.di.DI
import app.meetacy.di.builder.DIBuilder
import app.meetacy.di.builder.DIBuilderSingletonDelegate
import app.meetacy.di.builder.DIBuilderProviderDelegate
import app.meetacy.di.internal.LazyFactory
import kotlin.reflect.KProperty
import kotlin.reflect.KType
Expand Down Expand Up @@ -88,13 +88,13 @@ public inline fun <reified T1, reified T2, reified T3, reified T4, reified R> DI
name: String? = null,
crossinline factory: DI.(arg1: T1, arg2: T2, arg3: T3, arg4: T4) -> R
) {
singleton(name) {
provider(name) {
Factory4 { arg1: T1, arg2: T2, arg3: T3, arg4: T4 -> factory(arg1, arg2, arg3, arg4) }
}
}

public inline fun <reified T1, reified T2, reified T3, reified T4, reified R> DIBuilder.factory4(
public inline fun <reified T1, reified T2, reified T3, reified T4, reified R> DIBuilder.factory4provider(
crossinline factory: DI.(arg1: T1, arg2: T2, arg3: T3, arg4: T4) -> R
): DIBuilderSingletonDelegate<Factory4<T1, T2, T3, T4, R>> = singleton {
): DIBuilderProviderDelegate<Factory4<T1, T2, T3, T4, R>> = provider {
Factory4 { arg1: T1, arg2: T2, arg3: T3, arg4: T4 -> factory(arg1, arg2, arg3, arg4) }
}
6 changes: 3 additions & 3 deletions core/src/commonMain/kotlin/app/meetacy/di/factory/Factory5.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.meetacy.di.factory

import app.meetacy.di.DI
import app.meetacy.di.builder.DIBuilder
import app.meetacy.di.builder.DIBuilderSingletonDelegate
import app.meetacy.di.builder.DIBuilderProviderDelegate
import app.meetacy.di.internal.LazyFactory
import kotlin.reflect.KProperty
import kotlin.reflect.KType
Expand Down Expand Up @@ -95,13 +95,13 @@ public inline fun <reified T1, reified T2, reified T3, reified T4, reified T5, r
name: String? = null,
crossinline factory: DI.(arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) -> R
) {
singleton(name) {
provider(name) {
Factory5 { arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5 -> factory(arg1, arg2, arg3, arg4, arg5) }
}
}

public inline fun <reified T1, reified T2, reified T3, reified T4, reified T5, reified R> DIBuilder.factory5(
crossinline factory: DI.(arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) -> R
): DIBuilderSingletonDelegate<Factory5<T1, T2, T3, T4, T5, R>> = singleton {
): DIBuilderProviderDelegate<Factory5<T1, T2, T3, T4, T5, R>> = provider {
Factory5 { arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5 -> factory(arg1, arg2, arg3, arg4, arg5) }
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ composeRuntime = "1.3.3"
composeCompiler = "1.5.6"
lifecycle = "2.6.1"

mdi = "0.0.29"
mdi = "0.0.30"

[libraries]

Expand Down

0 comments on commit ee0c76d

Please sign in to comment.