Skip to content

Commit

Permalink
[feat] : 의존성 수동 주입
Browse files Browse the repository at this point in the history
  • Loading branch information
chanubc committed Jan 2, 2024
1 parent b6b5212 commit 24232f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.sopt.dosopttemplate.data.repositoryimpl

import org.sopt.dosopttemplate.data.service.ReqresService
import org.sopt.dosopttemplate.data.datasource.remote.ReqresDataSource
import org.sopt.dosopttemplate.domain.entity.ReqresEntity
import org.sopt.dosopttemplate.domain.repository.ReqresRepository

// 외부 데이터 소스(ReqresDataSource)로부터 데이터를 가져오고, 필요한 형태로 변환하여 비즈니스 로직 계층에게 제공
class ReqresRepositoryImpl constructor(private val reqresService: ReqresService) :
class ReqresRepositoryImpl(private val reqresDataSource: ReqresDataSource) :
ReqresRepository {
override suspend fun getReqresList(page: Int): Result<List<ReqresEntity>> {
return runCatching {
reqresService.getUserList(page).toReqresList()
reqresDataSource.getReqresList(page).toReqresList()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.sopt.dosopttemplate.utils
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import org.sopt.dosopttemplate.data.ApiFactory
import org.sopt.dosopttemplate.data.datasourceimpl.remote.ReqresDataSourceImpl
import org.sopt.dosopttemplate.data.repositoryimpl.AuthRepository
import org.sopt.dosopttemplate.data.repositoryimpl.ReqresRepositoryImpl
import org.sopt.dosopttemplate.ui.doandroid.DoAndroidViewModel
Expand All @@ -25,7 +26,8 @@ class ViewModelFactory :
}

modelClass.isAssignableFrom(DoAndroidViewModel::class.java) -> {
val repository = ReqresRepositoryImpl(ApiFactory.ServicePool.userService)
val repository =
ReqresRepositoryImpl(ReqresDataSourceImpl(ApiFactory.ServicePool.userService))
DoAndroidViewModel(repository) as T
}
// Add more ViewModel cases as needed
Expand Down

0 comments on commit 24232f5

Please sign in to comment.