bbaldino
04/29/2022, 4:59 PMApplication.configureRoutes()
-type method within a class to be able to add additional context? For example, I want to be able to fire events when a new websocket is established, so want a way to store a sort of ‘event emitter’, and therefore allow external entities to be able to subscribe to those events. I think maybe the new Context Receivers
would handle this? But looking for another way since those are still experimental.class MyClass {
private val eventHandlers = mutableListOf<EventHandler>()
fun addEventHandler(handler: EventHandler) {
eventHandlers += handler
}
fun Application.configureRoutes() {
webSocket("/ws") {
eventHandlers.forEach { it.websocketConnected() }
...
}
}
}
Landry Norris
05/01/2022, 8:08 PMbbaldino
05/02/2022, 3:11 PMJoost Klitsie
05/04/2022, 2:47 PMfun Application.module() {
val myClass = MyClass()
with(myClass) {
configureRoutes()
}
}
fun Application.module() {
val myClass = MyClass()
configureWebSockets(myClass)
}
fun Application.configureWebSockets(myClass: MyClass) {
webSocket("/ws") {
myClass.onWebSocketConnected() // <-- do something there within your myClass
}
}
fun Application.installRouting()
in these service classes