[P2][refactor] AppState service locator 사용 축소 및 handler별 context/interface 도입 #38

Closed
opened 2026-05-02 04:34:10 +00:00 by boxqkrtm · 1 comment

문제

AppState의 필드가 대부분 public이고 여러 계층에서 Arc<AppState> 또는 내부 Arc를 직접 꺼내 쓰는 service locator 형태입니다.

영향

  • 의존성 방향이 흐려짐
  • 테스트 double/fake 주입이 어려움
  • handler가 필요 이상의 권한/상태에 접근 가능
  • refactor 시 영향 범위가 커짐

제안

  • handler별 context struct 분리
  • 필요한 service만 trait/interface로 주입
  • AppState public field 최소화
  • public/admin/discovery/sdk 등 API surface별 dependency scope 축소

완료 기준

  • 신규 handler는 전체 AppState 대신 최소 context를 받음
  • 핵심 service trait에 대해 test double 주입 가능
  • public field 접근이 줄어듦

검토 기준: 업로드된 Rust portal-relay 코드 정적 리뷰. 리뷰 환경에서는 cargo check/test/clippy를 실행하지 못했습니다.

## 문제 `AppState`의 필드가 대부분 public이고 여러 계층에서 `Arc<AppState>` 또는 내부 Arc를 직접 꺼내 쓰는 service locator 형태입니다. ## 영향 - 의존성 방향이 흐려짐 - 테스트 double/fake 주입이 어려움 - handler가 필요 이상의 권한/상태에 접근 가능 - refactor 시 영향 범위가 커짐 ## 제안 - handler별 context struct 분리 - 필요한 service만 trait/interface로 주입 - `AppState` public field 최소화 - public/admin/discovery/sdk 등 API surface별 dependency scope 축소 ## 완료 기준 - 신규 handler는 전체 `AppState` 대신 최소 context를 받음 - 핵심 service trait에 대해 test double 주입 가능 - public field 접근이 줄어듦 --- 검토 기준: 업로드된 Rust `portal-relay` 코드 정적 리뷰. 리뷰 환경에서는 `cargo check/test/clippy`를 실행하지 못했습니다.
Owner

검토했지만 이번 범위에서는 수용하지 않습니다. AppState service locator 축소는 장기 설계 개선이지만, 현 relay compatibility 목표에 직접 필요한 변경은 아닙니다. 대규모 interface 분리는 테스트/호환성 리스크가 커서 닫습니다.

검토했지만 이번 범위에서는 수용하지 않습니다. AppState service locator 축소는 장기 설계 개선이지만, 현 relay compatibility 목표에 직접 필요한 변경은 아닙니다. 대규모 interface 분리는 테스트/호환성 리스크가 커서 닫습니다.
gofix closed this issue 2026-05-03 18:58:41 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
gofix/portal-tunnel-rs#38
No description provided.