How to inject the FragmentManger into interface in Android Fragment with Dagger Hilt?

36 Views Asked by At

I will show my sample code:

interface ErrorDialogInterface {
    fun show(title: String)
}

class ErrorDialogImpl @Inject constructor(
    private val fragmentManager: FragmentManager
) : ErrorDialogInterface {
    override fun show(title: String) {
        MyDialog.create().show(fragmentManager, TAG)
    }
}
class BaseFragmentWithError: Fragment() {
    @Inject lateinit var errorDialogInterface: ErrorDialogInterface
}

I want to inject the errorDialogInterface into the Fragment. However, its implementation contains the dynamic param (which is FragmentManager from Fragment).

Is it possible to do that with Dagger Hilt?

Thanks for supporting guys.

0

There are 0 best solutions below