mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-07 00:59:26 +00:00
initialize startup module
This commit is contained in:
17
startup/plugin/build.gradle
Normal file
17
startup/plugin/build.gradle
Normal file
@@ -0,0 +1,17 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
}
|
||||
|
||||
apply from: "$mppJavaProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api libs.koin
|
||||
api libs.kt.serialization
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
34
startup/plugin/src/commonMain/kotlin/ServerPlugin.kt
Normal file
34
startup/plugin/src/commonMain/kotlin/ServerPlugin.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
package dev.inmo.micro_utils.startup.plugin
|
||||
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
|
||||
@Serializable(ServerPlugin.Companion::class)
|
||||
interface ServerPlugin {
|
||||
fun Module.setupDI(config: JsonObject) {}
|
||||
|
||||
suspend fun Koin.startPlugin() {}
|
||||
|
||||
companion object : KSerializer<ServerPlugin> {
|
||||
override val descriptor: SerialDescriptor
|
||||
get() = String.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): ServerPlugin {
|
||||
val kclass = Class.forName(decoder.decodeString()).kotlin
|
||||
return (kclass.objectInstance ?: kclass.constructors.first { it.parameters.isEmpty() }.call()) as ServerPlugin
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: ServerPlugin) {
|
||||
encoder.encodeString(
|
||||
value::class.java.canonicalName
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user