-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65b0bee
commit 2a48792
Showing
3 changed files
with
50 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
core/data/src/main/java/camp/nextstep/edu/github/data/network/di/DataModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,16 @@ | ||
package camp.nextstep.edu.github.data.network.di | ||
|
||
import camp.nextstep.edu.github.data.network.GithubRepositoriesDataSource | ||
import camp.nextstep.edu.github.data.network.GithubService | ||
import camp.nextstep.edu.github.domain.network.GithubDataSource | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import okhttp3.OkHttpClient | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import java.util.concurrent.TimeUnit | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
abstract class DataModule { | ||
|
||
@Binds | ||
internal abstract fun bindDataSource(dataSource: GithubRepositoriesDataSource): GithubDataSource | ||
|
||
companion object { | ||
private const val BASE_URL = "https://api.github.com/" | ||
|
||
@Provides | ||
fun provideClient(): OkHttpClient { | ||
return OkHttpClient.Builder() | ||
.connectTimeout(1, TimeUnit.SECONDS) | ||
.readTimeout(1, TimeUnit.SECONDS) | ||
.writeTimeout(1, TimeUnit.SECONDS) | ||
.build() | ||
} | ||
|
||
@Provides | ||
fun provideGithubService(client: OkHttpClient): GithubService { | ||
return Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.client(client) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
.create(GithubService::class.java) | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
core/data/src/main/java/camp/nextstep/edu/github/data/network/di/NetworkModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package camp.nextstep.edu.github.data.network.di | ||
|
||
import camp.nextstep.edu.github.data.network.GithubService | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import okhttp3.OkHttpClient | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import java.util.concurrent.TimeUnit | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
abstract class NetworkModule { | ||
|
||
companion object { | ||
private const val BASE_URL = "https://api.github.com/" | ||
|
||
@Provides | ||
fun provideClient(): OkHttpClient { | ||
return OkHttpClient.Builder() | ||
.connectTimeout(1, TimeUnit.SECONDS) | ||
.readTimeout(1, TimeUnit.SECONDS) | ||
.writeTimeout(1, TimeUnit.SECONDS) | ||
.build() | ||
} | ||
|
||
@Provides | ||
fun provideGithubService(retrofit: Retrofit): GithubService { | ||
return retrofit.create(GithubService::class.java) | ||
} | ||
|
||
@Provides | ||
fun provideRetrofit(client: OkHttpClient): Retrofit { | ||
return Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.client(client) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
} | ||
} | ||
} |