-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
638 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.idea | ||
build | ||
.gradle | ||
.kotlin | ||
kotlin-js-store | ||
local.properties | ||
**/.DS_Store | ||
|
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
2 changes: 0 additions & 2 deletions
2
build-logic/src/main/kotlin/kmp-library-convention.gradle.kts
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
@file:Suppress("UNUSED_VARIABLE") | ||
|
||
plugins { | ||
kotlin("multiplatform") | ||
id("publication-convention") | ||
|
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
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
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
61 changes: 61 additions & 0 deletions
61
core/src/commonMain/kotlin/app/meetacy/di/factory/Factory0.kt
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,61 @@ | ||
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.internal.LazyFactory | ||
import kotlin.reflect.KProperty | ||
import kotlin.reflect.KType | ||
import kotlin.reflect.typeOf | ||
|
||
public fun interface Factory0<R> { | ||
public fun create(): R | ||
} | ||
|
||
// DI Extensions | ||
|
||
public fun <R> DI.create( | ||
factoryType: KType, | ||
name: String? = null | ||
): R = get<Factory0<R>>(factoryType, name).create() | ||
|
||
public inline fun <reified R> DI.create( | ||
name: String? = null | ||
): R = create(typeOf<Factory0<R>>(), name) | ||
|
||
// DI Delegates | ||
|
||
public inline fun <reified R> DI.creating(): Factory0Dependency<R> = | ||
Factory0Dependency( | ||
di = this, | ||
factoryType = typeOf<Factory0<R>>() | ||
) | ||
|
||
public class Factory0Dependency<R>( | ||
private val di: DI, | ||
private val factoryType: KType | ||
) { | ||
private val lazy = LazyFactory<R>() | ||
|
||
public operator fun getValue( | ||
thisRef: Any?, | ||
property: KProperty<*> | ||
): R = lazy.get { di.create(factoryType, property.name) } | ||
} | ||
|
||
// DIBuilder Extensions | ||
|
||
public inline fun <reified R> DIBuilder.factory0( | ||
name: String? = null, | ||
crossinline factory: DI.() -> R | ||
) { | ||
singleton(name) { | ||
Factory0 { factory() } | ||
} | ||
} | ||
|
||
public inline fun <reified R> DIBuilder.factory0( | ||
crossinline factory: DI.() -> R | ||
): DIBuilderSingletonDelegate<Factory0<R>> = singleton { | ||
Factory0 { factory() } | ||
} |
79 changes: 79 additions & 0 deletions
79
core/src/commonMain/kotlin/app/meetacy/di/factory/Factory1.kt
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,79 @@ | ||
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.internal.LazyFactory | ||
import kotlin.reflect.KProperty | ||
import kotlin.reflect.KType | ||
import kotlin.reflect.typeOf | ||
|
||
public fun interface Factory1<R1, T> { | ||
public fun create(arg1: R1): T | ||
} | ||
|
||
// DI Extensions | ||
|
||
public fun <T1, R> DI.create( | ||
factoryType: KType, | ||
arg1: T1, | ||
name: String? = null | ||
): R = get<Factory1<T1, R>>( | ||
type = factoryType, | ||
name = name | ||
).create(arg1) | ||
|
||
public inline fun <reified T1, reified R> DI.create( | ||
arg1: T1, | ||
name: String? = null | ||
): R = create( | ||
factoryType = typeOf<Factory1<T1, R>>(), | ||
arg1 = arg1, | ||
name = name | ||
) | ||
|
||
// DI Delegates | ||
|
||
public inline fun <reified T1, reified R> DI.creating( | ||
arg1: T1 | ||
): Factory1Dependency<T1, R> = Factory1Dependency( | ||
di = this, | ||
arg1 = arg1, | ||
factoryType = typeOf<Factory1<T1, R>>() | ||
) | ||
|
||
public class Factory1Dependency<T1, R>( | ||
private val di: DI, | ||
private val arg1: T1, | ||
private val factoryType: KType | ||
) { | ||
private val lazy = LazyFactory<R>() | ||
|
||
public operator fun getValue( | ||
thisRef: Any?, | ||
property: KProperty<*> | ||
): R = lazy.get { | ||
di.create( | ||
factoryType = factoryType, | ||
arg1 = arg1, | ||
name = property.name | ||
) | ||
} | ||
} | ||
|
||
// DIBuilder Extensions | ||
|
||
public inline fun <reified T1, reified R> DIBuilder.factory1( | ||
name: String? = null, | ||
crossinline factory: DI.(arg1: T1) -> R | ||
) { | ||
singleton(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 { | ||
Factory1 { arg1: T1 -> factory(arg1) } | ||
} |
Oops, something went wrong.