Skip to content

feat: add FastApiDepsStack for long-lived dependency resolution outside request context#4

Merged
ADR-007 merged 1 commit into
mainfrom
feat/deps-stack
May 24, 2026
Merged

feat: add FastApiDepsStack for long-lived dependency resolution outside request context#4
ADR-007 merged 1 commit into
mainfrom
feat/deps-stack

Conversation

@ADR-007

@ADR-007 ADR-007 commented May 23, 2026

Copy link
Copy Markdown
Owner

Adds FastApiDepsStack (async) and fastapi_depends_anywhere.sync.FastApiDepsStack (sync) — a stateful context manager that starts the FastAPI lifespan once, resolves multiple dependencies keeping them alive across calls, and tears everything down on close.

Usage

# async
async with FastApiDepsStack(app=app) as stack:
    db = await stack.resolve(DbDep)
    cache = await stack.resolve(CacheDep)

# sync
with sync.FastApiDepsStack(app=app) as stack:
    db = stack.resolve(DbDep)
    cache = stack.resolve(CacheDep)

Changes

  • fastapi_depends_anywhere/stack.py — async FastApiDepsStack
  • fastapi_depends_anywhere/sync/stack.py — sync wrapper delegating to async via _run_sync
  • Both exported from their respective __init__.py
  • 18 tests (9 async + 9 sync), 100% coverage

@github-actions

github-actions Bot commented May 23, 2026

Copy link
Copy Markdown

badge

Code Coverage Summary

Details
Filename                                      Stmts    Miss  Cover    Missing
------------------------------------------  -------  ------  -------  ---------
fastapi_depends_anywhere/__init__.py             12       0  100.00%
fastapi_depends_anywhere/_internal.py             7       0  100.00%
fastapi_depends_anywhere/config.py               20       0  100.00%
fastapi_depends_anywhere/core.py                 61       0  100.00%
fastapi_depends_anywhere/lifecycle.py            26       0  100.00%
fastapi_depends_anywhere/runners.py              18       0  100.00%
fastapi_depends_anywhere/stack.py                42       0  100.00%
fastapi_depends_anywhere/sync/__init__.py         5       0  100.00%
fastapi_depends_anywhere/sync/_loop.py           18       0  100.00%
fastapi_depends_anywhere/sync/core.py            85       0  100.00%
fastapi_depends_anywhere/sync/lifecycle.py       36       0  100.00%
fastapi_depends_anywhere/sync/runners.py         37       0  100.00%
fastapi_depends_anywhere/sync/stack.py           22       0  100.00%
TOTAL                                           389       0  100.00%

Diff against main

Filename                                     Stmts    Miss  Cover
-----------------------------------------  -------  ------  --------
fastapi_depends_anywhere/__init__.py            +1       0  +100.00%
fastapi_depends_anywhere/stack.py              +42       0  +100.00%
fastapi_depends_anywhere/sync/__init__.py       +1       0  +100.00%
fastapi_depends_anywhere/sync/stack.py         +22       0  +100.00%
TOTAL                                          +66       0  +100.00%

Results for commit: f6f3426

Minimum allowed coverage is 90%

♻️ This comment has been updated with latest results

@ADR-007 ADR-007 force-pushed the feat/deps-stack branch 2 times, most recently from 247b991 to 89955df Compare May 24, 2026 00:00
@ADR-007 ADR-007 force-pushed the feat/deps-stack branch from 89955df to f6f3426 Compare May 24, 2026 00:03
@ADR-007 ADR-007 merged commit ef1b63b into main May 24, 2026
6 checks passed
@ADR-007 ADR-007 deleted the feat/deps-stack branch May 24, 2026 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant