andrassama/dsh-omp-advisor/fastapi-dependency-injection
Claude Code and agent skill by andrassama/dsh-omp-advisor
- community
Checking that the SKILL.md file is still in the repository.
Equips the advisor to review FastAPI Depends() graphs for correct scoping, testability, and hidden coupling between the request lifecycle and business logic.
Install
npx vskill@latest install andrassama/dsh-omp-advisor/fastapi-dependency-injectionSKILL.md
The same SKILL.md was published earlier as andrassama/dsh-omp-advisor/fastapi-dependency-injection.
FastAPI Dependency Injection
FastAPI's Depends() graph is the backbone of request-scoped resource management: DB sessions, auth principals, and clients. A poorly designed graph leaks sessions, hides coupling behind globals, and makes tests impossible to isolate. Reviews should trace each dependency's lifecycle and its override story.
Watch for
- DB sessions created at module import or as globals instead of per-request dependencies.
yielddependencies missing cleanup (session not closed/rolled back on exception).- Business logic importing
Requestdirectly or reading globals instead of receiving injected deps. - Deep dependency chains where intermediate layers only forward arguments (DI theater).
- Dependencies doing heavy work (network calls) on every request with no caching.
- Auth dependencies that silently return
Noneinstead of raising 401/403. - Tests that monkeypatch internals instead of using
app.dependency_overrides. - Sync blocking dependencies declared
async def, stalling the event loop.
Best practices
- Provide the DB session via a
yielddependency that rolls back on error and always closes. - Keep dependencies small and composable: one for auth, one for pagination, one for the session.
- Make every external collaborator injectable so tests can swap it via
app.dependency_overrides. - Raise
HTTPExceptionin auth dependencies; never return sentinel values. - Use
Dependscaching deliberately; document when a dependency must re-run per request. - Declare sync blocking deps as plain
defso FastAPI runs them in the threadpool, not the event loop. - Type dependencies precisely with
Annotatedaliases so contracts are visible at the route signature. - Keep route handlers thin: parse via schema, delegate to a service layer receiving injected deps.
Quick checklist
- [ ] DB sessions are request-scoped
yielddependencies with guaranteed close. - [ ] Exceptions inside the request roll the session back.
- [ ] No business logic reads globals or constructs its own clients.
- [ ] Every external dependency is overridable in tests via
dependency_overrides. - [ ] Auth dependencies raise, never return None/sentinels.
- [ ] Sync blocking code lives in
defdeps, notasync def. - [ ] Repeated dependency chains are factored into Annotated aliases.
- [ ] Route handlers stay thin and delegate to injected services.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/fastapi-dependency-injection/SKILL.md
Popularity
- Repository stars
- 3
- 7-day trend score
- 12
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/andrassama/dsh-omp-advisor/fastapi-dependency-injection)