-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
5 changed files
with
170 additions
and
5 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
37 changes: 36 additions & 1 deletion
37
app/src/main/java/com/eshc/mygithubrepoapp/di/DataSourceModule.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,4 +1,39 @@ | ||
package com.eshc.mygithubrepoapp.di | ||
|
||
class DataSourceModule { | ||
import com.eshc.data.source.* | ||
import com.eshc.data.source.remote.* | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class DataSourceModule { | ||
|
||
@Binds | ||
abstract fun bindAuthDataSource( | ||
authDataSource : AuthDataSourceImpl | ||
) : AuthDataSource | ||
|
||
@Binds | ||
abstract fun bindIssueDataSource( | ||
issueDataSource : IssueDataSourceImpl | ||
) : IssueDataSource | ||
|
||
@Binds | ||
abstract fun bindNotificationDataSource( | ||
notificationDataSource : NotificationDataSourceImpl | ||
) : NotificationDataSource | ||
|
||
@Binds | ||
abstract fun bindRepoDataSource( | ||
repoDataSource: RepoDataSourceImpl | ||
) : RepoDataSource | ||
|
||
@Binds | ||
abstract fun bindUserDataSource( | ||
userDataSource: UserDataSourceImpl | ||
) : UserDataSource | ||
|
||
} |
66 changes: 65 additions & 1 deletion
66
app/src/main/java/com/eshc/mygithubrepoapp/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 |
---|---|---|
@@ -1,4 +1,68 @@ | ||
package com.eshc.mygithubrepoapp.di | ||
|
||
class NetworkModule { | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import okhttp3.OkHttpClient | ||
import retrofit2.CallAdapter | ||
import retrofit2.Converter | ||
import retrofit2.Retrofit | ||
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import java.util.concurrent.TimeUnit | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object NetworkModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideAuthRetrofit( | ||
okHttpClient: OkHttpClient, | ||
converter : Converter.Factory | ||
) : Retrofit { | ||
return Retrofit.Builder() | ||
.client(okHttpClient) | ||
.baseUrl("https://github.com") | ||
.addConverterFactory(converter) | ||
.build() | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideGithubRetrofit( | ||
okHttpClient: OkHttpClient, | ||
converter : Converter.Factory, | ||
callAdapter: CallAdapter.Factory | ||
) : Retrofit { | ||
return Retrofit.Builder() | ||
.client(okHttpClient) | ||
.baseUrl("https://api.github.com") | ||
.addConverterFactory(converter) | ||
.addCallAdapterFactory(callAdapter) | ||
.build() | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideConvertFactory(): Converter.Factory { | ||
return GsonConverterFactory.create() | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideCallAdapterFactory() : CallAdapter.Factory { | ||
return RxJava3CallAdapterFactory.create() | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideHttpClient() : OkHttpClient { | ||
return OkHttpClient.Builder() | ||
.connectTimeout(3,TimeUnit.SECONDS) | ||
.build() | ||
} | ||
|
||
} |
36 changes: 35 additions & 1 deletion
36
app/src/main/java/com/eshc/mygithubrepoapp/di/RepositoryModule.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,4 +1,38 @@ | ||
package com.eshc.mygithubrepoapp.di | ||
|
||
class RepositoryModule { | ||
import com.eshc.data.repository.* | ||
import com.eshc.domain.repository.* | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class RepositoryModule { | ||
|
||
@Binds | ||
abstract fun bindAuthRepository( | ||
authRepository : AuthRepositoryImpl | ||
) : AuthRepository | ||
|
||
@Binds | ||
abstract fun bindIssueRepository( | ||
issueRepository: IssueRepositoryImpl | ||
) : IssueRepository | ||
|
||
@Binds | ||
abstract fun bindNotificationRepository( | ||
notificationRepository: NotificationRepositoryImpl | ||
) : NotificationRepository | ||
|
||
@Binds | ||
abstract fun bindRepoRepository( | ||
repoRepository: RepoRepositoryImpl | ||
) : RepoRepository | ||
|
||
@Binds | ||
abstract fun bindUserRepository( | ||
userRepository: UserRepositoryImpl | ||
) : UserRepository | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/eshc/mygithubrepoapp/di/ServiceModule.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,22 @@ | ||
package com.eshc.mygithubrepoapp.di | ||
|
||
import com.eshc.data.source.remote.api.AuthService | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import retrofit2.Retrofit | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object ServiceModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideAuthService( | ||
retrofit: Retrofit | ||
) : AuthService { | ||
return retrofit.create(AuthService::class.java) | ||
} | ||
} |