T
T
Tsuzukeru2021-04-23 18:21:23
Android
Tsuzukeru, 2021-04-23 18:21:23

How to pass variable to DAG using new Dagger 2 API?

As far as I understand, the new Dagger 2 API is needed in order to remove the following code from the onCreate(Activity) and onAttach(Fragment ) methods:

(requireActivity().application as BaseApplication).appComponent.getPreviewComponent()
            .create().inject(this)


But what if you need to pass a value to the DAG at runtime? For example :
(requireActivity().application as BaseApplication).appComponent.getDetailComponent()
            .create(nasaId,requireContext()).inject(this)


How to implement it?

Read the documentation. There are no such examples. Do you have examples of projects where you can see it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-04-23
@Tsuzukeru

If you are talking about Hilt, then you do not need it :) But in principle, here is an example in the migration guide.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question