question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handling Retrofit multiple dependent providers

See original GitHub issue

I’not used to work with DI, but from theory point of view I decided to go to Toothpick for clarity and simplicity. However I got some issue resolving injection of Retrofit in my app.

I create a module “NetworkModule”

public class NetworkModule extends Module {
    public NetworkModule(String urlPath) {
        bind(Gson.class).toProvider(GsonProvider.class);
        bind(Retrofit.class).toProviderInstance(new RetrofitProvider(urlPath, new GsonProvider().get()));
}

As you see some providers depends from others. RetrofitProvider need previously injected Gson dependency. How to deal with that ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kelsoscommented, Sep 20, 2017

Try adding a inject annotation to the constructor of the provider. Toothpick needs the inject annotation on the constructor to create factories.

Something like this:

class GsonProvider 
@Inject
constructor(): Provider<Gson> {
...
}
0reactions
afaucogneycommented, Sep 21, 2017

@kelsos ok thank for the fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle multiple retrofit client using dagger hilt as dependency ...
First, here I see you have provide 2 instances of retrofit. Put the @Named annotation for each instance of the retrofit you provide....
Read more >
Modeling Retrofit Responses With Sealed Classes and ...
In this post, you will cover how to model Retrofit responses with Coroutines and Sealed classes to reduce code complexity and make your...
Read more >
Manual dependency injection - Android Developers
Basics of manual dependency injection; Managing dependencies with a container; Managing dependencies in application flows; Conclusion.
Read more >
Dagger 2 Android Example using Retrofit - GeeksforGeeks
Component: The connection between our dependency provider and dependency consumer is provided via an interface by annotating it with @Component.
Read more >
Consuming APIs with Retrofit | CodePath Android Cliffnotes
In the past, Retrofit relied on the Gson library to serialize and deserialize JSON data. Retrofit 2 now supports many different parsers for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found