Skip to content
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

Refactor/di container #150

Merged
merged 10 commits into from
Dec 13, 2022
Merged

Refactor/di container #150

merged 10 commits into from
Dec 13, 2022

Conversation

jinwoong16
Copy link
Collaborator

@jinwoong16 jinwoong16 commented Dec 12, 2022

📕 Issue Number

Close #143

📙 작업 내역

구현 내용 및 작업 했던 내역

  • Container 역할을 하는 프레임워크 생성
  • result builder를 사용하여 일괄적으로 dependancy를 register
  • property wrapper를 사용하여 dependancy를 resolve

📘 작업 유형

  • 신규 기능 추가
  • 버그 수정
  • 리펙토링
  • 문서 업데이트

📋 체크리스트

  • Merge 하는 브랜치가 올바른가?
  • 코딩컨벤션을 준수하는가?
  • PR과 관련없는 변경사항이 없는가?
  • 내 코드에 대한 자기 검토가 되었는가?
  • 변경사항이 효과적이거나 동작이 작동한다는 것을 보증하는 테스트를 추가하였는가?
  • 새로운 테스트와 기존의 테스트가 변경사항에 대해 만족하는가?

📝 PR 특이 사항

PR을 볼 때 주의깊게 봐야하거나 말하고 싶은 점

  • custom framework가 git에 푸시가 안되는 것 같아요. ignore에 포함된 것 같지는 않던데, 뭐가 문제일까요..?

  • custom framework인 DailyContainer은 Container.swift, Injected.swift, 그리고 InjectionKey.swift로 구성되어 있습니다.

  • Container.swift에서는 디펜던시를 등록하고, resolve하는 역할을 수행합니다.

  • Injected.swift에서는 property wrapper와 관련된 역할을 수행합니다.

  • InjectionKey.swift에서는 key를 기반으로 dependancy를 resolove할 수 있게 도와줍니다.

private extension HomeSceneDIContainer {
    func registerUseCase() {
        Container.shared.register {
            Module(QuestUseCaseKey.self) {
                @Injected(QuestRepositoryKey.self)
                var questRepository: QuestsRepository
                
                return DefaultQuestUseCase(questsRepository: questRepository)
            }
            
            Module(EnrollUseCaseKey.self) {
                @Injected(QuestRepositoryKey.self)
                var questRepository: QuestsRepository
                
                return DefaultEnrollUseCase(questsRepository: questRepository)
            }
            
            Module(UserUseCaseKey.self) {
                @Injected(UserRepositoryKey.self)
                var userRepository: UserRepository
                
                return DefaultUserUseCase(userRepository: userRepository)
            }
            
            Module(CalendarUseCaseKey.self) {
                @Injected(QuestRepositoryKey.self)
                var questRepository: QuestsRepository
                
                return HomeCalendarUseCase(questsRepository: questRepository)
            }
        }
    }
}
  • 현재 HomeScene의 UseCase를 해당 프레임워크를 사용하여 처리한 모습입니다. viewModel은 이 코드에서 등록된 use case를 property wrapper로 resolve하여 사용하고, view controller은 기존과 동일합니다. 이부분도 수정할지 여러분들의 의견이 궁금하네요.



@wickedRun
Copy link
Collaborator

고민하셨던 부분이 잘 해결된 거 같아서 좋습니다 고생하셨습니다.

@jinwoong16 jinwoong16 merged commit bc2bd7a into develop Dec 13, 2022
@jinwoong16 jinwoong16 deleted the refactor/DIContainer branch December 13, 2022 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DI 리팩토링
2 participants