♻️ refactor: FeedCrawler OOP 적용 #2
Merged
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.
📋 작업 내용
feed-crawler
main함수명 변경기존의
runCrawler라는 네이밍보다는main이 어울린다 생각하여 함수 명을 변경하였습니다.DatabaseConnection 인터페이스 작성
의존성 주입 방식을 위해서는 사용중인 Connection 객체들을 추상화 하여야 합니다.
이에따라
DatabaseConnection인터페이스를 생성하고, 사용할 수 있도록 처리하였습니다.feed-crawler에
tsyringe를 활용한 DI Container 도입기존 코드는 의존성을 가지는 클래스가 생성되어 있는 인스턴스를 직접 import해 사용했습니다.
이러한 모듈끼리의 강결합은 OOP의 SOLID 원칙중 Dependency Inversion Principle에 위배되며, 테스트와 유지보수에 영향을 줍니다.
그리하여 의존성을 외부에서 주입해주고자 했고, 이를 위해
DI Container (tsyringe)를 사용하기로 했습니다.왜
tsyringe인가요?tsyringe는 다른 NodeJS 진영 DI Container들 중 가벼운 편에 속하며, 커뮤니티가 가장 활성화 되어 있었습니다.(신뢰의 Microsoft)
생성자 주입 방식 쓰지 왜 굳이 DI Container 썼나요?
DI Container를 사용하면 개발자가 직접 객체 생성과 의존성 주입 코드를 수정할 일이 없습니다. 코드는 그대로 유지한 채 DI Container에 등록된 설정만 왔다 갔다 해주어 의존성을 손쉽게 관리할 수 있습니다.
npm 문서
📷 스크린 샷(선택 사항)