i wanted to inject dependency in my fragments how can i do this with dagger. i'm trying to get the activityComponent object from the MainActivity class. But if i have multiple classes using the same fragment do i need to type cast by checking the instance.Is there any simple way...
public class RepositoryFragment extends Fragment implements
RepositoryContract.View {
@Inject
RepositoryContract.Presenter presenter;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_repository, container, false);
// obtain Dagger 2 ActivityComponent from Actiity
ActivityComponent activityComponent = ((MainActivity)getActivity()).getActivityComponent();
// Inject dependencies
activityComponent.inject(this);
presenter.setView(this);
...
return view;
}
}