Skip to content

Instantly share code, notes, and snippets.

@viniciusalvesmello
Last active March 28, 2021 21:29
Show Gist options
  • Save viniciusalvesmello/3f14b3d64783806d6200255955aaf353 to your computer and use it in GitHub Desktop.
Save viniciusalvesmello/3f14b3d64783806d6200255955aaf353 to your computer and use it in GitHub Desktop.
Exemplo de MVP com o Hilt que gera o erro MissingBinding (Antes funcionava com o Dagger 2)
interface SampleRepository {
fun getSample(): String
}
class SampleRepositoryImpl: SampleRepository {
override fun getSample() = "Sample"
}
interface SamplePresenter {
fun initView()
}
class SamplePresenterImpl @Inject constructor(
private val sampleRepository: SampleRepository,
private val view: SampleView,
): SamplePresenter {
override fun initView() {
view.updateView(sampleRepository.getSample())
}
}
interface SampleView {
fun updateView(sample: String)
}
class SampleActivity : DaggerAppCompatActivity(), SampleView {
...
@Inject
lateinit var presenter: SamplePresenter
...
override fun onCreate(savedInstanceState: Bundle?) {
...
presenter.initView()
...
}
...
override fun updateView(sample: String) {
...
}
...
}
@Module
@InstallIn(ActivityComponent::class)
class SampleModule {
@Provides
fun provideSampleRepository(): SampleRepository = SampleRepositoryImpl()
@Provides
fun provideSampleView(view: SampleActivity): SampleView = view
@Provides
fun provideSamplePresenter(sampleRepository: SampleRepository, view: SampleView): SampleView = SamplePresenterImpl(sampleRepository, view)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment