mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-10-19 06:10:33 +00:00
add kdocs to the startup module
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
package dev.inmo.micro_utils.startup.plugin
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
|
||||
@Serializable(ServerPluginSerializer::class)
|
||||
interface ServerPlugin {
|
||||
fun Module.setupDI(config: JsonObject) {}
|
||||
|
||||
suspend fun startPlugin(koin: Koin) {}
|
||||
}
|
31
startup/plugin/src/commonMain/kotlin/StartPlugin.kt
Normal file
31
startup/plugin/src/commonMain/kotlin/StartPlugin.kt
Normal file
@@ -0,0 +1,31 @@
|
||||
package dev.inmo.micro_utils.startup.plugin
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
|
||||
/**
|
||||
* Default plugin for start of your app
|
||||
*/
|
||||
@Serializable(StartPluginSerializer::class)
|
||||
interface StartPlugin {
|
||||
/**
|
||||
* This method will be called first to configure [Koin] [Module] related to this plugin. You may use
|
||||
* [org.koin.core.scope.Scope.get] in your koin definitions like [Module.single] to retrieve
|
||||
* [kotlinx.coroutines.CoroutineScope], [kotlinx.serialization.json.Json] or [dev.inmo.micro_utils.startup.launcher.Config]
|
||||
*/
|
||||
fun Module.setupDI(config: JsonObject) {}
|
||||
|
||||
/**
|
||||
* This method will be called after all other [StartPlugin] will [setupDI]
|
||||
*
|
||||
* It is allowed to lock end of this method in case you require to prevent application to end its run (for example,
|
||||
* you are starting some web server)
|
||||
*
|
||||
* @param koin Will contains everything you will register in [setupDI] (as well as other [StartPlugin]s) and
|
||||
* [kotlinx.coroutines.CoroutineScope], [kotlinx.serialization.json.Json] and [dev.inmo.micro_utils.startup.launcher.Config]
|
||||
* by their types
|
||||
*/
|
||||
suspend fun startPlugin(koin: Koin) {}
|
||||
}
|
@@ -2,4 +2,4 @@ package dev.inmo.micro_utils.startup.plugin
|
||||
|
||||
import kotlinx.serialization.KSerializer
|
||||
|
||||
expect object ServerPluginSerializer : KSerializer<ServerPlugin>
|
||||
expect object StartPluginSerializer : KSerializer<StartPlugin>
|
@@ -6,16 +6,16 @@ import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
actual object ServerPluginSerializer : KSerializer<ServerPlugin> {
|
||||
actual object StartPluginSerializer : KSerializer<StartPlugin> {
|
||||
override val descriptor: SerialDescriptor
|
||||
get() = String.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): ServerPlugin {
|
||||
override fun deserialize(decoder: Decoder): StartPlugin {
|
||||
val kclass = Class.forName(decoder.decodeString()).kotlin
|
||||
return (kclass.objectInstance ?: kclass.constructors.first { it.parameters.isEmpty() }.call()) as ServerPlugin
|
||||
return (kclass.objectInstance ?: kclass.constructors.first { it.parameters.isEmpty() }.call()) as StartPlugin
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: ServerPlugin) {
|
||||
override fun serialize(encoder: Encoder, value: StartPlugin) {
|
||||
encoder.encodeString(
|
||||
value::class.java.canonicalName
|
||||
)
|
Reference in New Issue
Block a user