https://kotlinlang.org logo
#ktor
Title
# ktor
a

Alexander Weickmann

03/22/2022, 8:35 AM
Hello! Ktor config can be accessed via environment.config. But this can only be done from a place where we have the environment in scope. So for example in a route, we can do call.application.environment. But how best to access config deep down in the business layer? Do we have to pass the config via parameters or is there another way? We tried by reading the .conf file ourselves with ConfigFactory.load. But this has the disadvantage that the config cannot be changed dynamically in integration tests as described here: https://ktor.io/docs/testing.html#map
i

Ivan Aksenov

03/22/2022, 4:30 PM
What about to use a Koin library as Dependency Injection and inject your app config bean in service layers, like this ?
Copy code
val config: MyConfig by inject()
a

Alexander Weickmann

03/23/2022, 1:08 PM
that MyConfig bean would still be dependent on the environment.config instance. maybe if it is possible to construct such a MyConfig bean on application startup where we can pass that in, that might work
a

Aleksei Tirman [JB]

03/26/2022, 5:37 PM
Could you please explain why do you want to pass a server config to your business layer?
a

Alexander Weickmann

04/05/2022, 10:13 AM
Not a server config, a business layer config. something like "calculationLookbackDays" for some accounting engine
a

Aleksei Tirman [JB]

04/05/2022, 10:23 AM
Maybe you should store your business layer config separately from a server config.
4 Views