https://kotlinlang.org logo
#koin-contributors
Title
# koin-contributors
m

Marcello Galhardo

12/14/2021, 11:01 AM
Question: I see we can load properties from files or by manually adding it to Koin by using the DSL. However, from the DSL we can use the type system (it has a generic parameter) but from the file system it is always considered a String. However, when you load the properties you may run into runtime exceptions if you request a type from the file system property. (Please, see the print screen for the comparison). Is there a reason for this design? It feels really misleading and can cause runtime exceptions if you call the wrong combination. In my humble opinion, we should have 3 possible designs here: 1. All are properties typed (primitives). 2. All are untyped (Strings). 3. We separate the concepts of file system properties and normal properties - and each one of these have a different API (one typed and one untyped). What are your opinions?
a

arnaud.giuliani

12/17/2021, 9:31 AM
it’s a real topic 🙂 Something around since the first versions. Properties should be anything your want to share across as config constants
loading property file would load it from external file
m

Marcello Galhardo

12/17/2021, 3:38 PM
Yeah, my main problem is that there’s two versions of
getProperty
and if you call the wrong one you get an exception. For example, two examples will cause a runtime exception: First example: 1. You load a string from file. ie,
timeout=10
2. You read it with
getProperty<Int>("timeout")
. Second example: 1. You set a string using `setProperty<Int>(“timeout”, 10) 2. You read it with
getProperty("timeout")
. That happened few times in the codebase I’m working as they have a lot of properties (from file and defined in code). 😞
I will open a issue next days, so we can try to figure out how to fix it.
a

arnaud.giuliani

12/17/2021, 3:39 PM
Yeah, good catch. Need an update on that 👍
thanks for reporting an issue
5 Views