From 299ebff88bb4480074e511cbb15e6f00c4150ff2 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Mon, 3 Mar 2025 21:15:28 +0100 Subject: [PATCH] Refactor app configuration --- src/main/kotlin/eventDemo/Application.kt | 26 +++++-------------- src/main/kotlin/eventDemo/Configure.kt | 19 ++++++++++++++ .../{plugins/CommandHandler.kt => Init.kt} | 2 +- .../kotlin/eventDemo/app/actions/CardTest.kt | 6 ++--- 4 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 src/main/kotlin/eventDemo/Configure.kt rename src/main/kotlin/eventDemo/{plugins/CommandHandler.kt => Init.kt} (92%) diff --git a/src/main/kotlin/eventDemo/Application.kt b/src/main/kotlin/eventDemo/Application.kt index 2ee122f..6a3ec3c 100644 --- a/src/main/kotlin/eventDemo/Application.kt +++ b/src/main/kotlin/eventDemo/Application.kt @@ -1,27 +1,15 @@ package eventDemo -import eventDemo.plugins.configureCommandHandler -import eventDemo.plugins.configureHTTP -import eventDemo.plugins.configureKoin -import eventDemo.plugins.configureRouting -import eventDemo.plugins.configureSecurity -import eventDemo.plugins.configureSerialization -import eventDemo.plugins.configureSockets import io.ktor.server.application.Application import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty fun main() { - embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = Application::module, watchPaths = listOf("classes")) - .start(wait = true) -} - -fun Application.module() { - configureSecurity() - configureSerialization() - configureSockets() - configureHTTP() - configureRouting() - configureKoin() - configureCommandHandler() + embeddedServer( + factory = Netty, + port = 8080, + host = "0.0.0.0", + module = Application::configure, + watchPaths = listOf("classes"), + ).start(wait = true) } diff --git a/src/main/kotlin/eventDemo/Configure.kt b/src/main/kotlin/eventDemo/Configure.kt new file mode 100644 index 0000000..073cf83 --- /dev/null +++ b/src/main/kotlin/eventDemo/Configure.kt @@ -0,0 +1,19 @@ +package eventDemo + +import eventDemo.plugins.configureHTTP +import eventDemo.plugins.configureKoin +import eventDemo.plugins.configureRouting +import eventDemo.plugins.configureSecurity +import eventDemo.plugins.configureSerialization +import eventDemo.plugins.configureSockets +import io.ktor.server.application.Application + +fun Application.configure() { + configureSecurity() + configureSerialization() + configureSockets() + configureHTTP() + configureRouting() + configureKoin() + configureCommandHandler() +} diff --git a/src/main/kotlin/eventDemo/plugins/CommandHandler.kt b/src/main/kotlin/eventDemo/Init.kt similarity index 92% rename from src/main/kotlin/eventDemo/plugins/CommandHandler.kt rename to src/main/kotlin/eventDemo/Init.kt index 9bc4fc9..1d6ad2f 100644 --- a/src/main/kotlin/eventDemo/plugins/CommandHandler.kt +++ b/src/main/kotlin/eventDemo/Init.kt @@ -1,4 +1,4 @@ -package eventDemo.plugins +package eventDemo import eventDemo.app.actions.playNewCard.PlayCardCommandHandler import io.ktor.server.application.Application diff --git a/src/test/kotlin/eventDemo/app/actions/CardTest.kt b/src/test/kotlin/eventDemo/app/actions/CardTest.kt index 415a405..e82ce33 100644 --- a/src/test/kotlin/eventDemo/app/actions/CardTest.kt +++ b/src/test/kotlin/eventDemo/app/actions/CardTest.kt @@ -1,6 +1,6 @@ package eventDemo.app.actions -import eventDemo.module +import eventDemo.configure import eventDemo.shared.GameId import eventDemo.shared.entity.Card import eventDemo.shared.event.CardIsPlayedEvent @@ -27,7 +27,7 @@ class CardTest : testApplication { application { stopKoin() - module() + configure() } val id = GameId() @@ -52,7 +52,7 @@ class CardTest : val card: Card = Card.NumericCard(1, Card.Color.Blue) application { stopKoin() - module() + configure() val eventStream by inject() eventStream.publish( CardIsPlayedEvent(id, Card.NumericCard(2, Card.Color.Yellow)),