From c584c24fcee596df509368ef0718f139cea94429 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 15 Dec 2022 15:07:10 +0600 Subject: [PATCH] fixes and improvements --- .../launcher/src/commonMain/kotlin/Start.kt | 4 +-- .../kotlin/CreateStartupPluginAndRegister.kt | 26 ++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/startup/launcher/src/commonMain/kotlin/Start.kt b/startup/launcher/src/commonMain/kotlin/Start.kt index 7526adb8de9..fa22995d9dd 100644 --- a/startup/launcher/src/commonMain/kotlin/Start.kt +++ b/startup/launcher/src/commonMain/kotlin/Start.kt @@ -3,7 +3,7 @@ package dev.inmo.micro_utils.startup.launcher import dev.inmo.kslog.common.i import kotlinx.serialization.json.JsonObject import org.koin.core.KoinApplication -import org.koin.core.context.GlobalContext +import org.koin.core.context.startKoin import org.koin.dsl.module /** @@ -23,7 +23,7 @@ suspend fun start(rawConfig: JsonObject) { } ) logger.i("Modules loaded") - GlobalContext.startKoin(koinApp) + startKoin(koinApp) logger.i("Koin started") startPlugin(koinApp.koin) logger.i("App has been setup") diff --git a/startup/plugin/src/jsMain/kotlin/CreateStartupPluginAndRegister.kt b/startup/plugin/src/jsMain/kotlin/CreateStartupPluginAndRegister.kt index e8ea6b511ed..b4feec36747 100644 --- a/startup/plugin/src/jsMain/kotlin/CreateStartupPluginAndRegister.kt +++ b/startup/plugin/src/jsMain/kotlin/CreateStartupPluginAndRegister.kt @@ -1,5 +1,8 @@ package dev.inmo.micro_utils.startup.plugin +import com.benasher44.uuid.uuid4 +import kotlin.reflect.KClass + /** * Creates [T] using [block], register it in [StartPluginSerializer] using its [StartPluginSerializer.registerPlugin] * and returns created by [block] plugin @@ -7,8 +10,29 @@ package dev.inmo.micro_utils.startup.plugin * @param name Will be used as a key for registration in [StartPluginSerializer] and will be passed to the [block] as * parameter */ -inline fun createStartupPluginAndRegister(name: String, block: (String) -> T): T { +inline fun createStartupPluginAndRegister( + name: String = uuid4().toString(), + block: (String) -> T +): T { val plugin = block(name) StartPluginSerializer.registerPlugin(name, plugin) return plugin } + +/** + * Creates [T] using [block], register it in [StartPluginSerializer] using its [StartPluginSerializer.registerPlugin] + * and returns created by [block] plugin + */ +inline fun createStartupPluginAndRegister( + kClass: KClass, + name: String = uuid4().toString(), + block: (String) -> T +): T = createStartupPluginAndRegister("${kClass.simpleName}_$name", block) + +/** + * Creates [T] using [block], register it in [StartPluginSerializer] using its [StartPluginSerializer.registerPlugin] + * and returns created by [block] plugin + */ +inline fun createStartupPluginAndRegister( + block: (String) -> T +): T = createStartupPluginAndRegister(T::class, uuid4().toString(), block)