Hey guys, what is the best way to access Realm for...
# realm
Hey guys, what is the best way to access Realm for anywhere in the app? I don’t think calling the
every time is correct
i know to calling the realm for anywhere from app is not correct 😅
You can do something like https://github.com/joreilly/FantasyPremierLeague/blob/main/common/src/commonMain/kotlin/dev/johnoreilly/common/di/Koin.kt if you're using Koin (or similar if some other DI framework)
the project in a transitional stage to implement the dependency injection but for now we need to access the realm from different places
i found the solution with this class
Copy code
class RealmHelper {

    private val realmDB: Realm by lazy {

    private val realmEncDB: Realm by lazy {

    fun getRealm(): Realm {
        return realmDB

    fun getEncryptedRealm(): Realm {
        return realmEncDB

    companion object {

        private lateinit var instanceVar: RealmHelper
        val sharedInstance: RealmHelper
            get() {
                if (!::instanceVar.isInitialized) {
                    instanceVar = RealmHelper()
                return instanceVar