From claude-fastapi-guide-plugin
Internal conventions, abstractions, and anti-patterns for FastAPI's dependency-injection core under fastapi/dependencies/. Use when reading or modifying files in fastapi/dependencies/, when working with Dependant / solve_dependencies / get_dependant / analyze_param, when extending the DI system with a new injectable kind, or when debugging dependency caching, scoping, or callable dispatch.
How this skill is triggered — by the user, by Claude, or both
Slash command
/claude-fastapi-guide-plugin:fastapi-dependencies-internalsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
The dependency-injection core. [fastapi/dependencies/models.py](fastapi/dependencies/models.py) defines `Dependant` — a dataclass representing one callable's injection points. [fastapi/dependencies/utils.py](fastapi/dependencies/utils.py) holds `get_dependant` (build), `solve_dependencies` (evaluate), and the request-parameter parsers.
The dependency-injection core. fastapi/dependencies/models.py defines Dependant — a dataclass representing one callable's injection points. fastapi/dependencies/utils.py holds get_dependant (build), solve_dependencies (evaluate), and the request-parameter parsers.
Use this skill whenever the work touches the DI subsystem:
Dependant, solve_dependencies, get_dependant, analyze_param, request_params_to_args, request_body_to_argsuse_cache, cache_key), generator scopes (function / request), or sync/async dispatchDo not use this skill for general FastAPI request-flow questions — those go to the trace-data-flow or explain-feature skills. This one is specific to DI internals.
get_dependant introspects a callable via get_typed_signature + analyze_param and produces a Dependant tree. Side-effect-free.solve_dependencies walks the tree, recursively resolves sub-dependants, extracts path/query/header/cookie/body values, returns a SolvedDependency.Building must be side-effect-free; solving is async. Don't move work between phases.
Dependant (fastapi/dependencies/models.py:32) is effectively append-only after construction. Its @cached_property slots (is_coroutine_callable, is_gen_callable, is_async_gen_callable, cache_key, oauth_scopes) memoize on first access — mutating fields afterwards corrupts the cache. Build a new Dependant instead of editing one._unwrapped_call + _impartial to see through functools.partial and functools.wraps. Always use these helpers; raw inspect misses wrapped callables.DependencyCacheKey = (call, oauth_scopes, computed_scope) — per-request cache; Depends(..., use_cache=False) opts out."function" vs "request" (generators default to "request"). Cleanup runs via AsyncExitStacks on request.scope (fastapi_function_astack / fastapi_inner_astack).solve_dependencies)Per sub-dependant, the branch is chosen from Dependant's cached_property flags:
| Call shape | Branch |
|---|---|
| async generator | asynccontextmanager(call) → stack.enter_async_context |
| sync generator | contextmanager_in_threadpool(contextmanager(call)) → enter_async_context |
| coroutine function | await call(**values) |
| plain sync callable | await run_in_threadpool(call, **values) |
Every sync path goes through anyio — never call user code directly on the event loop.
fastapi._compat (ModelField, Undefined, …). No direct pydantic imports here — breaks v1 support.(values, errors); solve_dependencies aggregates them into one 422. Don't raise mid-parse for validation errors.get_dependant; preserve that path when adding fields to Dependant.Dependant after construction — cached_property will hand back stale data.analyze_param when adding a new injectable kind; classification lives in one place on purpose.async_exit_stack parameter of solve_dependencies despite the TODO — it's kept for external monkey-patching (the comment says so).solve_dependencies — async-first; bridge sync user code via run_in_threadpool / contextmanager_in_threadpool.solve_dependencies without forwarding dependency_cache — losing it silently double-executes deps and breaks use_cache=True.solve_dependencies, get_dependant, analyze_paramDependant dataclassskills/trace-data-flow/SKILL.md — sibling skill for end-to-end request tracesskills/explain-feature/SKILL.md — sibling skill for static feature explanationsnpx claudepluginhub x1nzhe/claude-fastapi-guide-plugin --plugin claude-fastapi-guide-pluginCreates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.