最近我开始在这里学习 kodein 依赖注入我正在尝试将数据加载到 ArrayList 中,然后将该 ArrayList 注入到所需的服务或活动中,但是我无法做到这一点并且面临运行时崩溃任何指导将不胜感激。!
我的服务等级:
class NotificationAccessibilityService() : AccessibilityService(),KodeinAware {
override val kodein: Kodein = Kodein.lazy{
import(AppModules().appModule(applicationContext))
}
val logger by instance<Logger>()
fun insertdata(){
//trying to insert data into arraylist
logger.list = ArrayList()
logger.list.add(mNodeInfo)
}
}
应用模块类:
class AppModules() {
fun appModule(context:Context) = Kodein.Module{
bind<Logger>() with singleton { AndroidLogger() }
}
}
记录仪接口:
interface Logger {
var list:ArrayList<AccessibilityNodeInfo>
}
记录器类:
class AndroidLogger() : Logger {
override var list: ArrayList<AccessibilityNodeInfo>
get() = TODO("not implemented")
set(value) {}
}
在我的活动中,我正在扩展 kodeinaware,然后尝试从 kodein 访问该 ArrayList,但是应用程序崩溃了:
class NormalCopy : AppCompatActivity(),KodeinAware {
override val kodein: Kodein by closestKodein()
val logger by kodein.instance<Logger>()
var accesslist = logger.list
}