Skip to content

Bind to the Fragment

Valery edited this page Aug 8, 2019 · 4 revisions

Bind the component to the Fragment is the same as bind the component to the Activity class.

  1. Implement the IHasComponent interface;
  2. Override the getComponent method;
  3. Override the getComponentKey method (if needed);
  4. Bind the component to the fragment.
class FragmentA : Fragment(), IHasComponent {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        XInjectionManager.instance
            .bindComponent<FeatureAComponent>(this)
            .inject(this)
    }

    override fun getComponent(): FeatureAComponent = 
        DaggerFeatureAComponent.builder().build()
}
Clone this wiki locally