What would be an idiomatic way to pass an Integer ...
# koin
h
What would be an idiomatic way to pass an Integer via injection using koin? I want to use/inject a counter in different components. I know that a direct pass by ref is not possible (https://stackoverflow.com/questions/51638871/pass-an-integer-by-reference-in-kotlin)
d
you could wrap it in a data class
Copy code
data class Counter(var value: Int)
☝️ 2
then inject the data class instead
be aware that doing that is not thread safe and that if you are using the counter in a multithreaded environment in the jvm, an
AtomicInteger
should be preferred.
h
Thanks for the great help @David Hernando
🤟 1
m
Could also use inline classes if performance is a consideration
inline class Counter(var value: Int)
https://kotlinlang.org/docs/reference/inline-classes.html