mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-18 14:47:15 +00:00
fixes and improvements
This commit is contained in:
parent
85e5cee154
commit
c584c24fce
@ -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")
|
||||
|
@ -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 <T : StartPlugin> createStartupPluginAndRegister(name: String, block: (String) -> T): T {
|
||||
inline fun <T : StartPlugin> 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 <T : StartPlugin> createStartupPluginAndRegister(
|
||||
kClass: KClass<T>,
|
||||
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 <reified T : StartPlugin> createStartupPluginAndRegister(
|
||||
block: (String) -> T
|
||||
): T = createStartupPluginAndRegister(T::class, uuid4().toString(), block)
|
||||
|
Loading…
Reference in New Issue
Block a user