this is idiomatically passing service class like this?:
Copy code
fun Application.myPlugin() {
routing {
post("/useful") {
val result = <mailto:this@myPlugin.myService.do|this@myPlugin.myService.do>()
call.respond(result)
}
}
}
val Application.myService get() = MyService(this)
class MyService(private val app: Application) {
fun do() { app.environment.config.property("app.i-can-use-app-props-here").getString() }
}
a
Aleksei Tirman [JB]
08/20/2023, 9:39 AM
I don't know whether this idiomatic or not but I would make a parameter for the service in the
Application.myPlugin
method and require only direct dependencies in the constructor of the service:
Copy code
fun Application.myPlugin(service: MyService) {
routing {
post("/useful") {
val result = service.doIt()
call.respond(result)
}
}
}
class MyService(private val appConfig: ApplicationConfig) {
fun doIt() {
appConfig.property("app.i-can-use-app-props-here").getString()
}
}