Hey guys, I'm trying to initialize my realm in hil...
# realm
y
Hey guys, I'm trying to initialize my realm in hilt like so:
Copy code
@Provides
    @Singleton
    fun provideLocalRealm(config: RealmConfiguration): Realm {
        return Realm.open(config)
    }
And inject it in my use cases... But I'm receiveing a error
java.lang.IllegalStateException: Scoped provider was invoked recursively returning different results: RealmImpl[/data/user/0/ee.visittallinn.tallinncard.dev/files/REALM_LOCAL}] & RealmImpl[/data/user/0/ee.visittallinn.tallinncard.dev/files/REALM_LOCAL}]. This is likely due to a circular dependency.
As I understood from documentation we could open the realm once and keep it as a singleton in the application lifecycle. Or I should open every time I need to use it and only inject the RealmConfiguration...?
c
Hmm, not 100% sure what is going on there. I haven’t used Hilt that much , but the error seems to come from there and complain that you are getting different instances somehow. Calling
Realm.open()
multiple times will return different instances, but I would assume that the
@Singleton
anotation cached the result? 🤔 But yes, you should be able to cache the result of
Realm.open()
and use it throughout.
y
I also assume the the singleton cache it as a Singleton implementation, but weird that is not working.
195 Views