将 Dagger 的 Singleton 对象设置为 null。

huangapple go评论67阅读模式
英文:

Set null to Dagger Singleton object

问题

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

Is the object null or will it be provided from the module again?

英文:

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?

答案1

得分: 0

Scoped dependencies (@Singleton in this case) are only generated once per Component instance and then re-used for any future injections. 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.

英文:

Scoped dependencies (@Singleton in this case) are only generated once per Component instance and then re-used for any future injections.<br/>
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.

huangapple
  • 本文由 发表于 2020年8月14日 20:47:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63413061.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定