Android Hilt cyclic dependencies

Viewed 51

I have cyclic dependencies error in the below sample code:

MyFragment.class

@AndroidEntryPoint
class MyFragment : Fragment():MyInterface{
...

@Inject
lateinit var myClass: MyClass

.....
}

I need to get a callback from MyClass into MyFragment.

MyClass.class

class MyClass @Inject constructor(val myInterface:MyInterface){
....
}

MyInterface.class

interface MyInterface{}

MyModule

@InstallIn(FragmentComponent::class)
@Module
abstract class MyModule {
   @Binds
  abstract fun provideCallback(callback: MyFragment): MyInterface
}
0 Answers
Related