Use Dagger 2 for Rest services
jaredsburrows opened this issue · comments
I rewrote the REST services to be injected through Dagger 2.
I added NetworkModule.java, (interface)Repository.java , GiphyService.java and removed ServiceUtil.java
Repository is injected so now
//MainFragment, Field Injection
@Inject Repository mRepository
...
...
...void loadTrendingImages(){
loadImages(mRepository.getTrendingResults())
}
GiphyService implements repository and the lower abstraction methods are now private
//Constructor injection
@Inject
public GiphyService(String accessToken, GiphyApiService service){...}
@OverRide
public Observable getTrendingResults(){
return getTrendingResults(mAccessToken);
// and lower abstractions such as limits, searches etc.
}
However I did not rewrite the GiphyServiceTest since I'm not yet totally sure how to do it with Dagger, but I'm working on learning it. If you know how to do it feel free to fix it
In the meantime you can check my fork here if you want
Ok cool. I will check it out!