Last active
March 28, 2021 21:29
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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