Skip to content

Commit

Permalink
Merge pull request #102 from FakeDevelopers/feature/BDBD-534
Browse files Browse the repository at this point in the history
FEAT : BDBD-534 Hilt Module Component Scope 변경
  • Loading branch information
minseonglove authored Feb 19, 2023
2 parents f0ab3c2 + e3e3fff commit 4b476a0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 63 deletions.
38 changes: 16 additions & 22 deletions data/src/main/java/com/fakedevelopers/data/di/ApiModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,17 @@ import javax.inject.Singleton

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class DataObject
annotation class NetworkObject

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class AuthDataObject
annotation class AuthNetworkObject

@Module
@InstallIn(SingletonComponent::class)
object ApiModule {

@DataObject
@Provides
fun provideBaseUrl() = BASE_URL

@DataObject
@NetworkObject
@Singleton
@Provides
fun provideNormalOkHttpClient(): OkHttpClient =
Expand All @@ -49,27 +45,26 @@ object ApiModule {
OkHttpClient.Builder().build()
}

@DataObject
@NetworkObject
@Singleton
@Provides
fun provideNormalRetrofit(
@DataObject okHttpClient: OkHttpClient,
@DataObject gson: Gson,
@DataObject baseUrl: String
@NetworkObject okHttpClient: OkHttpClient,
@NetworkObject gson: Gson
): Retrofit {
return Retrofit.Builder()
.client(okHttpClient)
.baseUrl(baseUrl)
.baseUrl(BASE_URL)
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build()
}

@AuthDataObject
@AuthNetworkObject
@Singleton
@Provides
fun provideAuthOkHttpClient(
@DataObject authInterceptor: LoginAuthInterceptor
@NetworkObject authInterceptor: LoginAuthInterceptor
): OkHttpClient =
if (BuildConfig.DEBUG.not()) {
val loggingInterceptor = HttpLoggingInterceptor()
Expand All @@ -84,28 +79,27 @@ object ApiModule {
.build()
}

@AuthDataObject
@AuthNetworkObject
@Singleton
@Provides
fun provideAuthRetrofit(
@AuthDataObject okHttpClient: OkHttpClient,
@DataObject gson: Gson,
@DataObject baseUrl: String
@AuthNetworkObject okHttpClient: OkHttpClient,
@NetworkObject gson: Gson
): Retrofit {
return Retrofit.Builder()
.client(okHttpClient)
.baseUrl(baseUrl)
.baseUrl(BASE_URL)
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build()
}

@DataObject
@NetworkObject
@Singleton
@Provides
fun provideGson(): Gson = GsonBuilder().setLenient().create()

@DataObject
@NetworkObject
@Singleton
@Provides
fun provideFirebaseAuth(): FirebaseAuth {
Expand All @@ -114,7 +108,7 @@ object ApiModule {
}
}

@DataObject
@NetworkObject
@Singleton
@Provides
fun provideAuthInterceptor(auth: FirebaseAuth) = LoginAuthInterceptor(auth)
Expand Down
29 changes: 14 additions & 15 deletions data/src/main/java/com/fakedevelopers/data/di/LoginModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,41 @@ import com.google.firebase.auth.FirebaseAuth
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import dagger.hilt.android.components.ActivityRetainedComponent
import dagger.hilt.android.scopes.ActivityRetainedScoped
import retrofit2.Retrofit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object LoginModule {

@Singleton
@InstallIn(ActivityRetainedComponent::class)
class LoginModule {
@ActivityRetainedScoped
@Provides
fun provideLoginWithEmailService(@DataObject retrofit: Retrofit): LoginWithEmailService =
fun provideLoginWithEmailService(@NetworkObject retrofit: Retrofit): LoginWithEmailService =
retrofit.create(LoginWithEmailService::class.java)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideLoginWithEmailRepository(service: LoginWithEmailService): LoginWithEmailRepository =
LoginWithEmailRepositoryImpl(service)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideLoginWithSocialService(@AuthDataObject retrofit: Retrofit): LoginWithSocialService =
fun provideLoginWithSocialService(@AuthNetworkObject retrofit: Retrofit): LoginWithSocialService =
retrofit.create(LoginWithSocialService::class.java)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideLoginWithSocialRepository(
service: LoginWithSocialService,
@DataObject auth: FirebaseAuth
@NetworkObject auth: FirebaseAuth
): LoginWithSocialRepository = LoginWithSocialRepositoryImpl(service, auth)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideTermsService(@DataObject retrofit: Retrofit): RegistrationTermService =
fun provideTermsService(@NetworkObject retrofit: Retrofit): RegistrationTermService =
retrofit.create(RegistrationTermService::class.java)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideTermsRepository(service: RegistrationTermService): RegistrationTermRepository =
RegistrationTermRepositoryImpl(service)
Expand Down
52 changes: 26 additions & 26 deletions data/src/main/java/com/fakedevelopers/data/di/MainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,93 +29,93 @@ import com.fakedevelopers.domain.repository.ProductSearchRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ActivityRetainedComponent
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import dagger.hilt.android.scopes.ActivityRetainedScoped
import retrofit2.Retrofit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object MainModule {
@InstallIn(ActivityRetainedComponent::class)
class MainModule {

@Singleton
@ActivityRetainedScoped
@Provides
fun provideProductListService(@DataObject retrofit: Retrofit): ProductListService =
fun provideProductListService(@NetworkObject retrofit: Retrofit): ProductListService =
retrofit.create(ProductListService::class.java)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideProductListRepository(service: ProductListService): ProductListRepository =
ProductListRepositoryImpl(service)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideProductEditorService(@AuthDataObject retrofit: Retrofit): ProductEditorService =
fun provideProductEditorService(@AuthNetworkObject retrofit: Retrofit): ProductEditorService =
retrofit.create(ProductEditorService::class.java)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideProductEditorRepository(service: ProductEditorService): ProductEditorRepository =
ProductEditorRepositoryImpl(service)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideProductDetailService(@DataObject retrofit: Retrofit): ProductDetailService =
fun provideProductDetailService(@NetworkObject retrofit: Retrofit): ProductDetailService =
retrofit.create(ProductDetailService::class.java)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideProductDetailRepository(service: ProductDetailService): ProductDetailRepository =
ProductDetailRepositoryImpl(service)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideImageRepository(@ApplicationContext context: Context): ImageRepository =
ImageRepositoryImpl(context.contentResolver)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideLocalStorageRepository(localStorageDataSource: LocalStorageDataSource): LocalStorageRepository =
LocalStorageRepositoryImpl(localStorageDataSource)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideLocalStorageDataSource(@ApplicationContext context: Context): LocalStorageDataSource =
LocalStorageDataSource(context)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideProductCategoryService(@DataObject retrofit: Retrofit): ProductCategoryService =
fun provideProductCategoryService(@NetworkObject retrofit: Retrofit): ProductCategoryService =
retrofit.create(ProductCategoryService::class.java)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideProductCategoryRepository(service: ProductCategoryService): ProductCategoryRepository =
ProductCategoryRepositoryImpl(service)

// 스트림 유저 토큰
@Singleton
@ActivityRetainedScoped
@Provides
fun provideChatService(@DataObject retrofit: Retrofit): ChatService =
fun provideChatService(@NetworkObject retrofit: Retrofit): ChatService =
retrofit.create(ChatService::class.java)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideChatRepository(service: ChatService): ChatRepository =
ChatRepositoryImpl(service)

// 인기 검색어 요청
@Singleton
@ActivityRetainedScoped
@Provides
fun provideProductSearchService(@DataObject retrofit: Retrofit): ProductSearchService =
fun provideProductSearchService(@NetworkObject retrofit: Retrofit): ProductSearchService =
retrofit.create(ProductSearchService::class.java)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideProductSearchRepository(service: ProductSearchService): ProductSearchRepository =
ProductSearchRepositoryImpl(service)

@Singleton
@ActivityRetainedScoped
@Provides
fun provideAlbumRepository(): AlbumRepository =
AlbumRepositoryImpl()
Expand Down

0 comments on commit 4b476a0

Please sign in to comment.