Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restart on Dagger 2 a dependency of Retrofits 2

I'm using dagger 2 and retrofit2 in a project that can change the country configurations and also the URL of the country you are pointing at for requesting data.

Is there any way Dagger2 can create again a Retrofit instance which will include the new URL?

So the idea is to restart the dependency of Retrofif whenever the user changes its country.

like image 607
Jose M Lechon Avatar asked Mar 13 '23 05:03

Jose M Lechon


1 Answers

Finally a solution that works. However I am not 100% sure about its performance cost.

Knowing that a user won't change the country too often or perhaps only once after installing the app, we can call again to DaggerAppComponent.builder().... .build() in the Custom Application class or whenever it is defined in a project. So once it instantiates again retrofit It will take the new URL.

As I said, this may have a cost of performance but this won't happen too often.

like image 146
Jose M Lechon Avatar answered Mar 24 '23 22:03

Jose M Lechon