refactor: single-source the connection-kind mapping off the providers#19
Merged
Merged
Conversation
build_di_container re-stated, via an isinstance ladder, the connection types and context keys that the context providers already carry. With modern-di 2.21.0 exposing ContextProvider.context_type, the registered providers are now the single source: setup_di registers them and build_di_container walks them, taking context_type and scope from each. Adding a connection kind is adding a provider; this dispatch no longer changes. Behavior is unchanged — existing Request and WebSocket tests cover it at 100%. Promotes the change into architecture/container-lifecycle.md and sharpens the glossary's Scope mapping entry, per the planning convention. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Completes candidate 1 from the architecture review (and finishes the single-sourcing #15 began). Behavior is unchanged.
What
build_di_containerre-stated, in anisinstanceladder, the connection types and context keys that the twoContextProviders already carry — the connection-kind concept lived in two places.modern-di 2.21.0 exposes
ContextProvider.context_type(modern-python/modern-di#244, shipped 2.21.0), so the registered providers can now be the single source:Adding a connection kind is now adding a provider to
_CONNECTION_PROVIDERS; the dispatch and registration both flow from it.Wins (in the review's terms)
isinstanceladder is absorbedChanges
modern_di_fastapi/main.py— the refactor above.pyproject.toml— floor bumpmodern-di>=2.21.0,<3(needs the publiccontext_type).architecture/container-lifecycle.md+architecture/glossary.md— promoted per the planning convention (the Scope mapping is now described as provider-sourced).Verification
just test-ci→ 100% coverage, 7 passed (existing Request + WebSocket tests cover the dispatch).just lint-ci→ ruff / ty / eof /check-planningall clean.🤖 Generated with Claude Code