sanevys
sanevys

Reputation: 569

It is good to have one realm across application?

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

Answers (1)

Christian Melchior
Christian Melchior

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

Related Questions