Konstant
Global access to the loaded config. Load it once at startup with the generated init<Spec> function, then read any spec, root or nested, from anywhere:
// At startup
Konstant.initAppConfig {
sources {
+EnvSource()
+TomlSource.fromResource("config.toml")
}
}
// Anywhere else, including nested specs
val db = Konstant.get<DatabaseConfig>()
val port = Konstant[AppConfig::class].server.portContent copied to clipboard
The configs are published once as an immutable snapshot, so reads are safe from any thread on every platform. Initializing twice fails; call reset between tests.