Reputation: 569
I would like to know is it good practice to use only one realm instance across application? (Dagger @Singleton) or does it has some kind flaws/drawbacks?
Upvotes: 0
Views: 299
Reputation: 20126
Both yes and no. Having one instance if fine, however Realms are thread confined which means that a true singleton (as the one provided by Dagger) will not work.
If you instead inject a thread local singleton it should work. That would however be be something you created yourself inside Daggers provide
methods as Dagger doesn't give you this out of the box as far as I know.
It would probably be easier to inject a new instance and remember to close it when done with it.
Upvotes: 1