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

manlan

11/24/2020, 5:41 PM
How do I access properties from
application.conf
from a non-Ktor object class?
j

Jorge R

11/24/2020, 6:13 PM
Maybe you can recover them at initial stage, create a config class and inject that class wherever you need it. Does it sound like a good option?
a

aleksey.tomin

11/25/2020, 2:57 AM
Copy code
import com.typesafe.config.ConfigFactory
...
config = ConfigFactory.load()
j

Jorge R

11/25/2020, 9:05 AM
Hi @aleksey.tomin Is there an easy way to disconnect from ConfigFactory to test later your code (is it an interface)? Is Ktor providing with a way to mock that config? Static calls are not that good when talking about testing.
👍 1
a

aleksey.tomin

11/25/2020, 9:07 AM
You can create
application.conf
in
test
directory
👍 1
j

Jorge R

11/25/2020, 9:15 AM
Ok, that could work as well. Pointing to an environment can be done using the config recovered, so all the test scenarios can be recreated after.
116 Views