Search code examples
javaandroidandroid-studiokotlindagger

Set null to Dagger Singleton object


If in class1 I set an object that Injected with Dagger and is @Singleton to null. And in class2 I Inject that object again.

Is the object null or it will provide from module again?


Solution

  • Scoped dependencies (@Singleton in this case) are only generated once per Component instance and then re-used for any future injections.
    So if you are using the same instance of your Component in class1 and class2, they'll get the same object, regardless of whether or not you nullify references to that object.