Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Dagger 2 for Rest services #1

Closed
jaredsburrows opened this issue Jul 2, 2016 · 2 comments
Closed

Use Dagger 2 for Rest services #1

jaredsburrows opened this issue Jul 2, 2016 · 2 comments

Comments

@jaredsburrows
Copy link
Owner

No description provided.

@egenvall
Copy link

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

@jaredsburrows
Copy link
Owner Author

Ok cool. I will check it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants