logo

python dependency injector

language-logoPython
language-logoFlask

• `update_station_service.py`에서 사용되는 repository 클래스들을 컨테이너에 등록한다. 이를 위해 `RepositoryContainer` 클래스를 생성하고, `GetStationRepository`와 `UpdateStationRepository`를 싱글톤으로 제공한다.
• 앱이 실행될 때 `RepositoryContainer`를 컨테이너에 할당한다. 이를 위해 `main.py`에서 `app.container = RepositoryContainer()`를 실행한다.
• `UpdateStationService` 클래스의 생성자에 `@inject` 데코레이터를 사용하여 의존성을 주입한다. 이를 통해 `GetStationRepository`와 `UpdateStationRepository`를 사용할 수 있다.
• `UpdateStationService` 클래스의 `update` 메소드에서는 `get_station_repository`를 통해 데이터를 가져오고, `update_station_repository`를 통해 데이터를 업데이트한다.

thumbnail
북마크
공유하기
신고하기
1분 분량
조회수 136
profile-image아이들미연
일 년 전
Copyright © 2025. Codenary All Rights Reserved.