Skip to content

Instantly share code, notes, and snippets.

@mohsenoid
Last active February 4, 2018 17:36
Show Gist options
  • Save mohsenoid/2fa179f7d64c8ba0c9a5516d66c8a0d2 to your computer and use it in GitHub Desktop.
Save mohsenoid/2fa179f7d64c8ba0c9a5516d66c8a0d2 to your computer and use it in GitHub Desktop.
package com.mirhoseini.marvel.domain;
/*...*/
@Module
public class ApiModule {
@Provides
@Singleton
public MarvelApi provideMarvelApi(Retrofit retrofit) {
return retrofit.create(MarvelApi.class);
}
@Provides
@Singleton
public Retrofit provideRetrofit(HttpUrl baseUrl, Converter.Factory converterFactory, CallAdapter.Factory callAdapterFactory, OkHttpClient okHttpClient) {
return new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(converterFactory)
.addCallAdapterFactory(callAdapterFactory)
.client(okHttpClient)
.build();
}
@Provides
@Singleton
public Converter.Factory provideGsonConverterFactory(Gson gson) {
return GsonConverterFactory.create(gson);
}
@Singleton
@Provides
public Gson provideGson() {
return new Gson();
}
@Provides
@Singleton
public CallAdapter.Factory provideRxJavaCallAdapterFactory() {
return RxJavaCallAdapterFactory.create();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment