一、 dagger2 使用无法自动生成dagger + component 问题
一般两种方法进行注册:
方法一:
实体类 Product 构造方法:
class Product @Inject constructor() {
fun showPro(): String {
return "shb##@@"
}
}
桥梁 component:
@Component
interface ProductComponent {
fun inject(mainActivity: MainActivity) {}
}
方法二:
实体类Stu:(没什么变化)
class Stu {
val msg = "Stu 的实例是注解方式注入的"
fun showMessage(): String {
return msg
}
}
module中添加@provides注解
@Module
class StuModule {
@Singleton
@Provides
fun provideStu(): Stu {
return Stu()
}
}
桥梁component,关联module