I am trying to implement Realm Version management with dagger2, with this link Adavis Realm Migration, but getting following error,
[Dagger/MissingBinding] java.util.Map> cannot be provided without an @Provides-annotated method. public abstract interface CoreComponent { ^
The codes are as follows,
interface VersionMigration {
fun migrate(realm: DynamicRealm, oldVersion: Long)
}
class RealmVersion1Migration @Inject constructor(): VersionMigration {
override fun migrate(realm: DynamicRealm, oldVersion: Long) {
val schema = realm.schema
if (0 == oldVersion.toInt()) {
schema.create("RealmAlbumEntity")
.addField("album_id", String::class.java, FieldAttribute.PRIMARY_KEY)
Timber.e("migration V1 complete")
}
}
}
@Reusable
class ERealmMigration @Inject constructor(
private val versionMigrations:
Map<Int, Provider<VersionMigration>>
) : RealmMigration {
init {
Timber.e("IN Realm Migration")
}
override fun migrate(
realm: DynamicRealm,
oldVersion: Long,
newVersion: Long
) {
for (i in oldVersion.toInt() until newVersion) {
val provider: Provider<VersionMigration> = versionMigrations.getValue(i.toInt())
val versionMigration = provider.get()
versionMigration.migrate(realm, i)
}
}
}
This is my included module in realmConfig, private const val REALM_SCHEMA = 1L
@Module(includes = [MigrationsModule::class])
class RealmConfigModule {
@Provides
@AppScope
fun provideRealm(realmConfiguration: RealmConfiguration): Realm {
return Realm.getInstance(realmConfiguration)
}
@Provides
@AppScope
fun provideRealmConfiguration(
@Named(CONTEXT_APPLICATION) application: Application,
realmMigration: ERealmMigration
): RealmConfiguration {
val config = RealmConfiguration.Builder().name(application.getString(R.string.real_db_name))
.schemaVersion(REALM_SCHEMA)
.migration(realmMigration)
.modules(UserRealmModule(), EventRealmModule())
.build()
Realm.setDefaultConfiguration(config)
return config
}
}
And this is my AppComponent,
@Component(modules = [RealmConfigModule::class])
@AppScope
interface CoreComponent {
@Component.Factory
interface Factory {
fun create(@BindsInstance application: Application): CoreComponent
}
}
I had tried to get through following links, but not able to gather any usefull contents out of it. Link 1 Link 2 Link 3