-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AN/USER] refactor: Hilt 적용(#453) #454
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f11fbd6
chore: Hilt 의존성 추가
EmilyCh0 e5b88a2
feat: 의존성 주입 모듈 추가
EmilyCh0 f3705d4
feat: 의존성 주입에 hilt 적용
EmilyCh0 2be9fcb
refactor: 사용하지 않는 수동 di 코드 삭제
EmilyCh0 3cca614
chore: ktlintcheck
EmilyCh0 8bd56d9
refactor: 불필요한 어노테이션 제거
EmilyCh0 9b8a261
refactor: 뷰모델 스코프 모듈 분리
EmilyCh0 c466dd7
chore: 싱글톤 모듈 패키지 이동
EmilyCh0 4b0fb36
refactor: BaseUrlQualifier 추가
EmilyCh0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
44 changes: 2 additions & 42 deletions
44
android/festago/app/src/main/java/com/festago/festago/FestagoApplication.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,58 +1,18 @@ | ||
package com.festago.festago | ||
|
||
import android.app.Application | ||
import com.festago.festago.analytics.FirebaseAnalyticsHelper | ||
import com.festago.festago.di.AnalysisContainer | ||
import com.festago.festago.di.AuthServiceContainer | ||
import com.festago.festago.di.LocalDataSourceContainer | ||
import com.festago.festago.di.NormalServiceContainer | ||
import com.festago.festago.di.RepositoryContainer | ||
import com.festago.festago.di.TokenContainer | ||
import com.kakao.sdk.common.KakaoSdk | ||
import dagger.hilt.android.HiltAndroidApp | ||
|
||
@HiltAndroidApp | ||
class FestagoApplication : Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
initKakaoSdk() | ||
initRepositoryContainer() | ||
initFirebaseContainer() | ||
} | ||
|
||
private fun initKakaoSdk() { | ||
KakaoSdk.init(this, BuildConfig.KAKAO_NATIVE_APP_KEY) | ||
} | ||
|
||
private fun initRepositoryContainer() { | ||
normalServiceContainer = NormalServiceContainer(BuildConfig.BASE_URL) | ||
|
||
tokenContainer = TokenContainer( | ||
normalServiceContainer = normalServiceContainer, | ||
localDataSourceContainer = LocalDataSourceContainer(applicationContext), | ||
) | ||
|
||
authServiceContainer = AuthServiceContainer( | ||
baseUrl = BuildConfig.BASE_URL, | ||
tokenContainer = tokenContainer, | ||
) | ||
|
||
repositoryContainer = RepositoryContainer( | ||
authServiceContainer = authServiceContainer, | ||
normalServiceContainer = normalServiceContainer, | ||
tokenContainer = tokenContainer, | ||
) | ||
} | ||
|
||
private fun initFirebaseContainer() { | ||
FirebaseAnalyticsHelper.init(applicationContext) | ||
analysisContainer = AnalysisContainer() | ||
} | ||
|
||
companion object DependencyContainer { | ||
lateinit var normalServiceContainer: NormalServiceContainer | ||
lateinit var authServiceContainer: AuthServiceContainer | ||
lateinit var repositoryContainer: RepositoryContainer | ||
lateinit var analysisContainer: AnalysisContainer | ||
lateinit var tokenContainer: TokenContainer | ||
} | ||
} |
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
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
30 changes: 30 additions & 0 deletions
30
android/festago/app/src/main/java/com/festago/festago/data/di/ViewModelScopeModule.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,30 @@ | ||
package com.festago.festago.data.di | ||
|
||
import com.festago.festago.data.repository.ReservationTicketDefaultRepository | ||
import com.festago.festago.data.repository.StudentVerificationDefaultRepository | ||
import com.festago.festago.data.repository.UserDefaultRepository | ||
import com.festago.festago.repository.ReservationTicketRepository | ||
import com.festago.festago.repository.StudentVerificationRepository | ||
import com.festago.festago.repository.UserRepository | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.components.ViewModelComponent | ||
import dagger.hilt.android.scopes.ViewModelScoped | ||
|
||
@InstallIn(ViewModelComponent::class) | ||
@Module | ||
interface ViewModelScopeModule { | ||
|
||
@Binds | ||
@ViewModelScoped | ||
fun bindsReservationTicketDefaultRepository(reservationTicketRepository: ReservationTicketDefaultRepository): ReservationTicketRepository | ||
|
||
@Binds | ||
@ViewModelScoped | ||
fun bindsStudentVerificationDefaultRepository(studentVerificationRepository: StudentVerificationDefaultRepository): StudentVerificationRepository | ||
|
||
@Binds | ||
@ViewModelScoped | ||
fun binsUserDefaultRepository(userRepository: UserDefaultRepository): UserRepository | ||
} |
19 changes: 19 additions & 0 deletions
19
...d/festago/app/src/main/java/com/festago/festago/data/di/singletonscope/AnalyticsModule.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,19 @@ | ||
package com.festago.festago.data.di.singletonscope | ||
|
||
import com.festago.festago.analytics.AnalyticsHelper | ||
import com.festago.festago.analytics.FirebaseAnalyticsHelper | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
interface AnalyticsModule { | ||
@Binds | ||
@Singleton | ||
fun bindsFirebaseAnalyticsHelper( | ||
analyticsHelper: FirebaseAnalyticsHelper | ||
): AnalyticsHelper | ||
} |
65 changes: 65 additions & 0 deletions
65
android/festago/app/src/main/java/com/festago/festago/data/di/singletonscope/ApiModule.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,65 @@ | ||
package com.festago.festago.data.di.singletonscope | ||
|
||
import com.festago.festago.BuildConfig | ||
import com.festago.festago.data.retrofit.AuthInterceptor | ||
import com.festago.festago.data.retrofit.TokenManager | ||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.OkHttpClient | ||
import retrofit2.Retrofit | ||
import javax.inject.Qualifier | ||
import javax.inject.Singleton | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class NormalRetrofitQualifier | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class AuthRetrofitQualifier | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class BaseUrlQualifier | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
object ApiModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideOkHttpClient(tokenManager: TokenManager): OkHttpClient = OkHttpClient | ||
.Builder() | ||
.addInterceptor(AuthInterceptor(tokenManager)) | ||
.build() | ||
|
||
@Provides | ||
@Singleton | ||
@NormalRetrofitQualifier | ||
fun providesNormalRetrofit(@BaseUrlQualifier baseUrl: String): Retrofit = Retrofit.Builder() | ||
.baseUrl(baseUrl) | ||
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) | ||
.build() | ||
|
||
@Provides | ||
@Singleton | ||
@AuthRetrofitQualifier | ||
fun providesAuthRetrofit( | ||
@BaseUrlQualifier baseUrl: String, | ||
okHttpClient: OkHttpClient | ||
): Retrofit = Retrofit.Builder() | ||
.baseUrl(baseUrl) | ||
.client(okHttpClient) | ||
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) | ||
.build() | ||
|
||
@Provides | ||
@Singleton | ||
@BaseUrlQualifier | ||
fun providesBaseUrl(): String = BuildConfig.BASE_URL | ||
} |
17 changes: 17 additions & 0 deletions
17
.../festago/app/src/main/java/com/festago/festago/data/di/singletonscope/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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.festago.festago.data.di.singletonscope | ||
|
||
import com.festago.festago.data.datasource.TokenDataSource | ||
import com.festago.festago.data.datasource.TokenLocalDataSource | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
interface DataSourceModule { | ||
@Binds | ||
@Singleton | ||
fun bindsLocalTokenDataSource(tokenDataSource: TokenLocalDataSource): TokenDataSource | ||
} |
40 changes: 40 additions & 0 deletions
40
.../festago/app/src/main/java/com/festago/festago/data/di/singletonscope/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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.festago.festago.data.di.singletonscope | ||
|
||
import com.festago.festago.data.repository.AuthDefaultRepository | ||
import com.festago.festago.data.repository.FestivalDefaultRepository | ||
import com.festago.festago.data.repository.SchoolDefaultRepository | ||
import com.festago.festago.data.repository.TicketDefaultRepository | ||
import com.festago.festago.data.repository.TokenDefaultRepository | ||
import com.festago.festago.repository.AuthRepository | ||
import com.festago.festago.repository.FestivalRepository | ||
import com.festago.festago.repository.SchoolRepository | ||
import com.festago.festago.repository.TicketRepository | ||
import com.festago.festago.repository.TokenRepository | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
interface RepositoryModule { | ||
|
||
@Binds | ||
fun bindsTokenDefaultRepository(tokenRepository: TokenDefaultRepository): TokenRepository | ||
|
||
@Binds | ||
fun bindsAuthDefaultRepository(authRepository: AuthDefaultRepository): AuthRepository | ||
|
||
@Binds | ||
@Singleton | ||
fun bindsFestivalDefaultRepository(festivalRepository: FestivalDefaultRepository): FestivalRepository | ||
|
||
@Binds | ||
@Singleton | ||
fun bindsSchoolDefaultRepository(schoolRepository: SchoolDefaultRepository): SchoolRepository | ||
|
||
@Binds | ||
@Singleton | ||
fun bindsTicketDefaultRepository(ticketRepository: TicketDefaultRepository): TicketRepository | ||
} |
67 changes: 67 additions & 0 deletions
67
...oid/festago/app/src/main/java/com/festago/festago/data/di/singletonscope/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,67 @@ | ||
package com.festago.festago.data.di.singletonscope | ||
|
||
import com.festago.festago.data.service.FestivalRetrofitService | ||
import com.festago.festago.data.service.ReservationTicketRetrofitService | ||
import com.festago.festago.data.service.StudentVerificationRetrofitService | ||
import com.festago.festago.data.service.TicketRetrofitService | ||
import com.festago.festago.data.service.TokenRetrofitService | ||
import com.festago.festago.data.service.UserRetrofitService | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import retrofit2.Retrofit | ||
import javax.inject.Singleton | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
object ServiceModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun providesFestivalRetrofitService( | ||
@NormalRetrofitQualifier retrofit: Retrofit | ||
): FestivalRetrofitService { | ||
return retrofit.create(FestivalRetrofitService::class.java) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun providesTokenRetrofitService( | ||
@NormalRetrofitQualifier retrofit: Retrofit | ||
): TokenRetrofitService { | ||
return retrofit.create(TokenRetrofitService::class.java) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun providesReservationTicketRetrofitService( | ||
@NormalRetrofitQualifier retrofit: Retrofit | ||
): ReservationTicketRetrofitService { | ||
return retrofit.create(ReservationTicketRetrofitService::class.java) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun providesTicketRetrofitService( | ||
@AuthRetrofitQualifier retrofit: Retrofit | ||
): TicketRetrofitService { | ||
return retrofit.create(TicketRetrofitService::class.java) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun providesUserRetrofitService( | ||
@AuthRetrofitQualifier retrofit: Retrofit | ||
): UserRetrofitService { | ||
return retrofit.create(UserRetrofitService::class.java) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun providesStudentVerificationRetrofitService( | ||
@AuthRetrofitQualifier retrofit: Retrofit | ||
): StudentVerificationRetrofitService { | ||
return retrofit.create(StudentVerificationRetrofitService::class.java) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
반환 타입이 원시 타입이라 Qualifier를 미리 정의하는건 어떤가요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BaseUrlQualifier 추가 완료!