mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-17 22:39:25 +00:00
Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
ea9dbf2371 | |||
d34e3ec7a9 | |||
c8833a36af | |||
a067cb0c0f | |||
999c8327bd | |||
c2ec73c70a | |||
702f782fc1 | |||
25dbcaaf83 | |||
b00d454a24 | |||
dbc921d56d | |||
438fefa7a3 | |||
5d74eac814 | |||
9fb62e1e25 | |||
3e366ea73b | |||
0ff895bffa | |||
c5bb120280 |
21
CHANGELOG.md
21
CHANGELOG.md
@@ -1,5 +1,26 @@
|
||||
# Changelog
|
||||
|
||||
## 0.19.0
|
||||
|
||||
* `Versions`:
|
||||
* `Korlibs`: `4.0.1`
|
||||
|
||||
## 0.18.4
|
||||
|
||||
* `Koin`:
|
||||
* New extension `lazyInject`
|
||||
|
||||
## 0.18.3
|
||||
|
||||
* `Versions`:
|
||||
* `Serialization`: `1.5.0` -> `1.5.1`
|
||||
* `Android Cor Ktx`: `1.10.0` -> `1.10.1`
|
||||
|
||||
## 0.18.2
|
||||
|
||||
* `Startup`:
|
||||
* Now internal `Json` is fully customizable
|
||||
|
||||
## 0.18.1
|
||||
|
||||
* `Common`:
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package dev.inmo.micro_utils.crypto
|
||||
|
||||
import com.soywiz.krypto.md5
|
||||
import korlibs.crypto.md5
|
||||
|
||||
typealias MD5 = String
|
||||
|
||||
|
@@ -14,5 +14,5 @@ crypto_js_version=4.1.1
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.18.1
|
||||
android_code_version=192
|
||||
version=0.19.0
|
||||
android_code_version=196
|
||||
|
@@ -1,7 +1,7 @@
|
||||
[versions]
|
||||
|
||||
kt = "1.8.20"
|
||||
kt-serialization = "1.5.0"
|
||||
kt-serialization = "1.5.1"
|
||||
kt-coroutines = "1.6.4"
|
||||
|
||||
kslog = "1.1.1"
|
||||
@@ -10,7 +10,7 @@ jb-compose = "1.4.0"
|
||||
jb-exposed = "0.41.1"
|
||||
jb-dokka = "1.8.10"
|
||||
|
||||
korlibs = "3.4.0"
|
||||
korlibs = "4.0.1"
|
||||
uuid = "0.7.0"
|
||||
|
||||
ktor = "2.3.0"
|
||||
@@ -22,12 +22,12 @@ koin = "3.4.0"
|
||||
okio = "3.3.0"
|
||||
|
||||
ksp = "1.8.20-1.0.11"
|
||||
kotlin-poet = "1.13.0"
|
||||
kotlin-poet = "1.13.2"
|
||||
|
||||
android-gradle = "7.4.2"
|
||||
dexcount = "4.0.0"
|
||||
|
||||
android-coreKtx = "1.10.0"
|
||||
android-coreKtx = "1.10.1"
|
||||
android-recyclerView = "1.3.0"
|
||||
android-appCompat = "1.6.1"
|
||||
android-fragment = "1.5.7"
|
||||
|
40
koin/src/commonMain/kotlin/GetWithDefinition.kt
Normal file
40
koin/src/commonMain/kotlin/GetWithDefinition.kt
Normal file
@@ -0,0 +1,40 @@
|
||||
package dev.inmo.micro_utils.koin
|
||||
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.definition.BeanDefinition
|
||||
import org.koin.core.definition.KoinDefinition
|
||||
import org.koin.core.instance.InstanceFactory
|
||||
import org.koin.core.parameter.ParametersDefinition
|
||||
import org.koin.core.scope.Scope
|
||||
|
||||
fun <T> Koin.get(definition: BeanDefinition<T>, parameters: ParametersDefinition? = null): T = get(
|
||||
definition.primaryType,
|
||||
definition.qualifier,
|
||||
parameters
|
||||
)
|
||||
|
||||
fun <T> Koin.get(definition: InstanceFactory<T>, parameters: ParametersDefinition? = null): T = get(
|
||||
definition.beanDefinition,
|
||||
parameters
|
||||
)
|
||||
|
||||
fun <T> Koin.get(definition: KoinDefinition<T>, parameters: ParametersDefinition? = null): T = get(
|
||||
definition.factory,
|
||||
parameters
|
||||
)
|
||||
|
||||
fun <T> Scope.get(definition: BeanDefinition<T>, parameters: ParametersDefinition? = null): T = get(
|
||||
definition.primaryType,
|
||||
definition.qualifier,
|
||||
parameters
|
||||
)
|
||||
|
||||
fun <T> Scope.get(definition: InstanceFactory<T>, parameters: ParametersDefinition? = null): T = get(
|
||||
definition.beanDefinition,
|
||||
parameters
|
||||
)
|
||||
|
||||
fun <T> Scope.get(definition: KoinDefinition<T>, parameters: ParametersDefinition? = null): T = get(
|
||||
definition.factory,
|
||||
parameters
|
||||
)
|
27
koin/src/jvmMain/kotlin/LazyInject.kt
Normal file
27
koin/src/jvmMain/kotlin/LazyInject.kt
Normal file
@@ -0,0 +1,27 @@
|
||||
package dev.inmo.micro_utils.koin
|
||||
|
||||
import org.koin.core.parameter.ParametersDefinition
|
||||
import org.koin.core.qualifier.Qualifier
|
||||
import org.koin.java.KoinJavaComponent
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
fun <T> lazyInject(
|
||||
kClassFactory: () -> KClass<*>,
|
||||
qualifier: Qualifier? = null,
|
||||
parameters: ParametersDefinition? = null
|
||||
): Lazy<T> {
|
||||
return lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
|
||||
KoinJavaComponent.get(kClassFactory().java, qualifier, parameters)
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> lazyInject(
|
||||
kClass: KClass<*>,
|
||||
qualifier: Qualifier? = null,
|
||||
parameters: ParametersDefinition? = null
|
||||
): Lazy<T> = lazyInject({ kClass }, qualifier, parameters)
|
||||
|
||||
inline fun <reified T> lazyInject(
|
||||
qualifier: Qualifier? = null,
|
||||
noinline parameters: ParametersDefinition? = null
|
||||
): Lazy<T> = lazyInject(T::class, qualifier, parameters)
|
@@ -1,6 +1,6 @@
|
||||
package dev.inmo.micro_utils.ktor.common
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import korlibs.time.DateTime
|
||||
|
||||
typealias FromToDateTime = Pair<DateTime?, DateTime?>
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package dev.inmo.micro_utils.ktor.server
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import korlibs.time.DateTime
|
||||
import dev.inmo.micro_utils.ktor.common.FromToDateTime
|
||||
import io.ktor.http.Parameters
|
||||
|
||||
|
@@ -2,6 +2,7 @@ plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "application"
|
||||
id "com.google.devtools.ksp"
|
||||
}
|
||||
|
||||
apply from: "$mppJvmJsLinuxMingwProjectPresetPath"
|
||||
@@ -11,6 +12,7 @@ kotlin {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api internalProject("micro_utils.startup.plugin")
|
||||
api internalProject("micro_utils.koin")
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
@@ -29,3 +31,10 @@ java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
dependencies {
|
||||
add("kspCommonMainMetadata", project(":micro_utils.koin.generator"))
|
||||
}
|
||||
|
||||
ksp {
|
||||
}
|
||||
|
@@ -0,0 +1,38 @@
|
||||
// THIS CODE HAVE BEEN GENERATED AUTOMATICALLY
|
||||
// TO REGENERATE IT JUST DELETE FILE
|
||||
// ORIGINAL FILE: StartLauncherPlugin.kt
|
||||
package dev.inmo.micro_utils.startup.launcher
|
||||
|
||||
import kotlin.Boolean
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.definition.Definition
|
||||
import org.koin.core.definition.KoinDefinition
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.core.qualifier.named
|
||||
import org.koin.core.scope.Scope
|
||||
|
||||
/**
|
||||
* @return Definition by key "baseJsonProvider"
|
||||
*/
|
||||
public val Scope.baseJsonProvider: Json?
|
||||
get() = getOrNull(named("baseJsonProvider"))
|
||||
|
||||
/**
|
||||
* @return Definition by key "baseJsonProvider"
|
||||
*/
|
||||
public val Koin.baseJsonProvider: Json?
|
||||
get() = getOrNull(named("baseJsonProvider"))
|
||||
|
||||
/**
|
||||
* Will register [definition] with [org.koin.core.module.Module.single] and key "baseJsonProvider"
|
||||
*/
|
||||
public fun Module.baseJsonProviderSingle(createdAtStart: Boolean = false, definition: Definition<Json>):
|
||||
KoinDefinition<Json> = single(named("baseJsonProvider"), createdAtStart = createdAtStart, definition
|
||||
= definition)
|
||||
|
||||
/**
|
||||
* Will register [definition] with [org.koin.core.module.Module.factory] and key "baseJsonProvider"
|
||||
*/
|
||||
public fun Module.baseJsonProviderFactory(definition: Definition<Json>): KoinDefinition<Json> =
|
||||
factory(named("baseJsonProvider"), definition = definition)
|
@@ -1,9 +1,11 @@
|
||||
@file:GenerateKoinDefinition("baseJsonProvider", Json::class)
|
||||
package dev.inmo.micro_utils.startup.launcher
|
||||
|
||||
import dev.inmo.kslog.common.i
|
||||
import dev.inmo.kslog.common.taggedLogger
|
||||
import dev.inmo.kslog.common.w
|
||||
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||
import dev.inmo.micro_utils.koin.annotations.GenerateKoinDefinition
|
||||
import dev.inmo.micro_utils.startup.launcher.StartLauncherPlugin.setupDI
|
||||
import dev.inmo.micro_utils.startup.launcher.StartLauncherPlugin.startPlugin
|
||||
import dev.inmo.micro_utils.startup.plugin.StartPlugin
|
||||
@@ -13,9 +15,10 @@ import kotlinx.coroutines.joinAll
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.serialization.SerialFormat
|
||||
import kotlinx.serialization.StringFormat
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.decodeFromJsonElement
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.modules.SerializersModule
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.KoinApplication
|
||||
import org.koin.core.context.startKoin
|
||||
@@ -35,7 +38,20 @@ object StartLauncherPlugin : StartPlugin {
|
||||
single { rawJsonObject }
|
||||
single { config }
|
||||
single { CoroutineScope(Dispatchers.Default) }
|
||||
single { defaultJson } binds arrayOf(StringFormat::class, SerialFormat::class)
|
||||
single {
|
||||
val serializersModules = getAll<SerializersModule>().distinct()
|
||||
val baseJson = baseJsonProvider ?: defaultJson
|
||||
if (serializersModules.isEmpty()) {
|
||||
baseJson
|
||||
} else {
|
||||
Json(baseJson) {
|
||||
serializersModule = SerializersModule {
|
||||
include(baseJson.serializersModule)
|
||||
serializersModules.forEach { include(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
} binds arrayOf(StringFormat::class, SerialFormat::class)
|
||||
|
||||
includes(
|
||||
config.plugins.mapNotNull {
|
||||
|
Reference in New Issue
Block a user