FIX: Use dependencies.py service factories in API handlers#75
Open
FIX: Use dependencies.py service factories in API handlers#75
Conversation
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
service = FooService(db)construction in everyapp/api/v1/*.pyhandler withDepends(get_xxx_service)fromapp/dependencies.py.app/dependencies.py:get_api_key_serviceandget_job_service.get_snapshot_serviceto pass the Redis singleton, removing a hand-rolledSnapshotService(db, epics, redis)in the sync snapshot-creation path.service = PVService(db)line inGET /v1/pvs/search(the local variable was never used).Motivation
app/dependencies.pyalready definedget_pv_service,get_snapshot_service, andget_tag_service, but handlers ignored them and re-instantiated services inline on every request — see examples in app/api/v1/tags.py and app/api/v1/snapshots.py before this change. That pattern made each handler carry extra boilerplate, obscured the real dependency graph, and made it harder to swap services in tests (the test fixtures already overrideget_dbandget_epics_service, andDepends-style factories let those overrides cascade automatically).This PR is a pure refactor: observable behavior is unchanged, so the full integration test suite passes without any test-side edits. It also lays groundwork for the follow-up envelope-removal work in #32 / slaclab/react-squirrel#77 — that PR touches every endpoint once, and having them all already go through
Depends(get_xxx_service)means the diff per handler stays small.Closes #50.
Where Has This Been Documented?
This change is internal refactoring with no user-visible surface change, so no doc updates were needed. The new factory names are self-documenting via their existing neighbors in
app/dependencies.py.Pre-merge checklist