Skip to content

refactor: single-source connection->scope mapping#15

Merged
lesnik512 merged 1 commit into
mainfrom
chore/single-source-connection-scope
Jun 26, 2026
Merged

refactor: single-source connection->scope mapping#15
lesnik512 merged 1 commit into
mainfrom
chore/single-source-connection-scope

Conversation

@lesnik512

Copy link
Copy Markdown
Member

What

Single-sources the connection→scope mapping in build_di_container: instead of hardcoding Scope.REQUEST / Scope.SESSION, it derives each child container's scope from the providers (fastapi_request_provider.scope / fastapi_websocket_provider.scope). The Request↔REQUEST / WebSocket↔SESSION pairing now lives in exactly one place — the ContextProvider definitions.

The scope: Scope | None = None annotation becomes a plain scope = None (inferred IntEnum | None), since AbstractProvider.scope is statically IntEnum.

Why

The scope a connection's child container is built at must match the scope its ContextProvider reads from, but the pairing was written twice with nothing enforcing agreement — a latent drift hazard. Deriving the scope from the provider makes them agree by construction.

This mirrors the same change just shipped in modern-di-litestar (#22) — the two integrations carry the identical pattern. (modern-di-faststream already eliminated the analogous writer/reader drift by naming its shared container keys.)

Behavior

Unchanged. The if Request / elif WebSocket structure and the scope=None default for any other connection are preserved exactly — only the scope source changes. The ContextProvider definitions are untouched.

Checks

  • just lint-ci — clean (ruff, ty)
  • just test-ci — 7 passed, 100% line coverage

Net 0 lines (3 insertions, 3 deletions).

@lesnik512 lesnik512 merged commit ad6c62f into main Jun 26, 2026
6 checks passed
@lesnik512 lesnik512 deleted the chore/single-source-connection-scope branch June 26, 2026 09:41
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