Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dagger 2 Producers
@ProducerModule
public class GithubApiProducerModule {
@Produces
static OkHttpClient produceOkHttpClient() {
final OkHttpClient.Builder builder = new OkHttpClient.Builder();
if (BuildConfig.DEBUG) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.addInterceptor(logging);
}
builder.connectTimeout(60 * 1000, TimeUnit.MILLISECONDS)
.readTimeout(60 * 1000, TimeUnit.MILLISECONDS);
return builder.build();
}
@Produces
public Retrofit produceRestAdapter(Application application, OkHttpClient okHttpClient) {
Retrofit.Builder builder = new Retrofit.Builder();
builder.client(okHttpClient)
.baseUrl(application.getString(R.string.endpoint))
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create());
return builder.build();
}
@Produces
public GithubApiService produceGithubApiService(Retrofit restAdapter) {
return restAdapter.create(GithubApiService.class);
}
@Produces
public UserManager produceUserManager(GithubApiService githubApiService) {
return new UserManager(githubApiService);
}
@Produces
public UserModule.Factory produceUserModuleFactory(GithubApiService githubApiService) {
return new UserModule.Factory(githubApiService);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.