This plugin is used to retrieve preferences from outside of ktor's Application class.
See README at the top.
fun Application.module() {
install(EnvironmentPlugin) {
config = environment.config
}
}
object Example : EnvironmentComponent {
val foo by inject<String>("example.foo")
fun baz() {
val bar by injectOrDefault<Int>("example.bar", 0)
val decimalList by injectList<BigDecimal>("example.decimalList")
}
}
The following types are currently available for injection.
- String
- Byte
- Short
- Int
- Long
- Float
- Double
- Boolean
- BigInteger
- BigDecimal
- java.time.LocalDate
- java.time.LocalDateTime
- java.time.LocalTime
- kotlinx.datetime.LocalDate (※1)
- kotlinx.datetime.LocalDateTime (※1)
- kotlinx.datetime.LocalTime (※1)
※1 To use them, add kotlinx-datetime as a dependency.