What’s the kotlin way to do singletons? I know abo...
# announcements
d
What’s the kotlin way to do singletons? I know about `object`s but they’re not easy to test, or inject dependencies into ( unless i’m misunderstanding something ).
d
The "Kotlin way" would be
object
. If you want the singleton to have injected dependencies, then you'll probably want to use a dependency injection framework like Dagger2.
y
to be specific: If you want DI, you do singletons exactly like you would in java.
g
If you want DI than you don't need Singletons, like in Java or like
object
Not easy to test or if you need DI means that you overuse Singletons for classes that should be just ordinary class, injected as dependency to another class and amount of instances regulated by your DI graph