我有一个android
应用程序,它是在 kotlin 中开发的,我们也使用kodein
依赖项来绑定数据。当第一次绑定数据时,它会正确绑定,但在第二次调用时不会绑定。
inner class CallmyClass() : MultiDexApplication(), KodeinAware {
val diModel = Kodein.Module {
bind<ExchangeRateProvider>() with singleton { CryptoCompareExchangeProvider(this@App, instance()) }
bind<SyncProgressProvider>() with singleton { SyncProgressProvider() }
bind<WallethKeyStore>() with singleton { keyStore }
bind<Settings>() with singleton { KotprefSettings }
bind<CurrentTokenProvider>() with singleton { CurrentTokenProvider(instance()) }
bind<AppDatabase>() with singleton { Room.databaseBuilder(applicationContext, AppDatabase::class.java, "maindb").build() }
bind<NetworkDefinitionProvider>() with singleton { NetworkDefinitionProvider(instance()) }
bind<CurrentAddressProvider>() with singleton { InitializingCurrentAddressProvider(keyStore, instance(), instance(), applicationContext,1) }
bind<FourByteDirectory>() with singleton { FourByteDirectoryImpl(instance(), applicationContext) }
}
val appDiModule = Kodein.Module(allowSilentOverride = true) {
import(diModel)
}
override val kodein: Kodein = Kodein {
import(appDiModule)
}
}
问题是,第一次绑定时,此代码将执行
bind<CurrentAddressProvider>() with singleton { InitializingCurrentAddressProvider(keyStore, instance(), instance(), applicationContext,i) }
"InitializingCurrentAddressProvider()"
这个类调用并成功执行。
但是当我尝试调用这些线路时
bind<CurrentAddressProvider>() with singleton { InitializingCurrentAddressProvider(keyStore, instance(), instance(), applicationContext,i) }
在第二次执行该行但
"InitializingCurrentAddressProvider()"
这个类不执行。这就是问题所在,如果第二个类是执行意味着我将得到结果,那么结果将自动绑定。但它不执行。