Refactor app configuration

This commit is contained in:
2025-03-03 21:15:28 +01:00
parent de3d4a1021
commit 299ebff88b
4 changed files with 30 additions and 23 deletions

View File

@@ -1,27 +1,15 @@
package eventDemo 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.application.Application
import io.ktor.server.engine.embeddedServer import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty import io.ktor.server.netty.Netty
fun main() { fun main() {
embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = Application::module, watchPaths = listOf("classes")) embeddedServer(
.start(wait = true) factory = Netty,
} port = 8080,
host = "0.0.0.0",
fun Application.module() { module = Application::configure,
configureSecurity() watchPaths = listOf("classes"),
configureSerialization() ).start(wait = true)
configureSockets()
configureHTTP()
configureRouting()
configureKoin()
configureCommandHandler()
} }

View File

@@ -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()
}

View File

@@ -1,4 +1,4 @@
package eventDemo.plugins package eventDemo
import eventDemo.app.actions.playNewCard.PlayCardCommandHandler import eventDemo.app.actions.playNewCard.PlayCardCommandHandler
import io.ktor.server.application.Application import io.ktor.server.application.Application

View File

@@ -1,6 +1,6 @@
package eventDemo.app.actions package eventDemo.app.actions
import eventDemo.module import eventDemo.configure
import eventDemo.shared.GameId import eventDemo.shared.GameId
import eventDemo.shared.entity.Card import eventDemo.shared.entity.Card
import eventDemo.shared.event.CardIsPlayedEvent import eventDemo.shared.event.CardIsPlayedEvent
@@ -27,7 +27,7 @@ class CardTest :
testApplication { testApplication {
application { application {
stopKoin() stopKoin()
module() configure()
} }
val id = GameId() val id = GameId()
@@ -52,7 +52,7 @@ class CardTest :
val card: Card = Card.NumericCard(1, Card.Color.Blue) val card: Card = Card.NumericCard(1, Card.Color.Blue)
application { application {
stopKoin() stopKoin()
module() configure()
val eventStream by inject<GameEventStream>() val eventStream by inject<GameEventStream>()
eventStream.publish( eventStream.publish(
CardIsPlayedEvent(id, Card.NumericCard(2, Card.Color.Yellow)), CardIsPlayedEvent(id, Card.NumericCard(2, Card.Color.Yellow)),