Dagger injection not working for “object” in Kotlin

If you look into kotlin bytecode you’ll find that the code you’ve written is translated into following:

public final class SomeSingleton {
    public static LProperty; property // <- Notice static field here

    public final getProperty()LProperty
    ...

    public final setProperty(LProperty)V
    ...
}

As you can see the actual field is static which makes it uneligible for instance injection. You may try to move @Inject annotation onto setter method by doing so:

object SomeSingleton {
    @set:Inject
    lateinit var property: Property
    ...
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)