How to MVP in Dagger Hilt?

﹥>﹥吖頭↗ 提交于 2020-08-10 19:45:45

问题


I can't compile the code using a Model View Presenter(MVP) Hilt approach.

I get this error: /MotionPoC/app/build/generated/source/kapt/debug/com/aria/motionpoc/di/MotionApp_HiltComponents.java:145: error: [Dagger/MissingBinding] com.aria.motionpoc.coupon.MainActivity cannot be provided without an @Inject constructor or an @Provides-annotated method. This type supports members injection but cannot be implicitly provided.

The code itself:

MainActivity.kt

@AndroidEntryPoint
class MainActivity : AppCompatActivity(), MainContract.View {

    @Inject
    lateinit var presenter: MainContract.Presenter

MainPresenter.kt

class MainPresenter @Inject constructor(
    private val view: MainContract.View
): MainContract.Presenter {

    override fun onViewCreated() {
        view.showList()
    }
}

MainModule.kt

@InstallIn(ActivityComponent::class)
@Module
abstract class MainModule {

    @Binds
    abstract fun bindActivity(view: MainActivity): MainContract.View

    @Binds
    abstract fun bindPresenter(impl: MainPresenter): MainContract.Presenter
}

MotionApp.kt

@HiltAndroidApp
open class MotionApp : Application()

来源:https://stackoverflow.com/questions/63306914/how-to-mvp-in-dagger-hilt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!