♻️ refactor(di): pre-instantiate DI providers and clean up project#79
Conversation
Centralize Dishka provider instantiation in the DI module instead of duplicating it at each usage site (API app, bot, tests). This reduces boilerplate and ensures consistent provider configuration. Also removes outdated plan documents, updates .gitignore, and refreshes local test config. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Code Review: refactor(di) pre-instantiate DI providers The core goal is solid: eliminating the repeated loop at every call site is a genuine cleanup. Issues: 1. I18nProvider now included in the API container infra_providers now includes I18nProvider(), which is also injected into the Litestar API container via *infra_providers. Previously I18nProvider was only wired up in the bot. If I18nProvider reads .ftl files or initialises FluentTranslatorHub at provide-time, this will either silently waste resources on every API startup or raise FileNotFoundError if locale data is not accessible. Worth verifying the API container actually needs i18n, or splitting infra_providers into bot_infra_providers and api_infra_providers if the two entry points need different providers. 2. Shared provider instances across multiple containers The same list objects (infra_providers, interactor_providers) are passed into make_async_container() in app.py, bot/main.py, and conftest.py. For stateless Dishka providers this is fine, but if any provider ever holds per-container state, sharing instances will cause subtle cross-contamination. Worth a comment so a future provider author does not get surprised. 3. docs added wholesale to .gitignore Adding docs to .gitignore ignores the entire docs/ directory going forward. Any future documentation committed under docs/ will not be tracked. If docs/ is genuinely no longer used this is fine, but it is an irreversible broad gate. 4. Minor: .gitignore still missing trailing newline. What is Good:
Questions:
|
The config-local.yaml was accidentally committed with local credentials (test_dev_user/test_dev_password/test_dev_db) that don't match the CI Postgres service (dev_user/dev_password/ask_app), causing all integration tests to fail with InvalidPasswordError. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ch CI" This reverts commit d8dd889.
CI service container credentials (dev_user/dev_password/ask_app) were out of sync with config-local.yaml (test_dev_user/test_dev_password/ test_dev_db), causing integration tests to fail with InvalidPasswordError. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Code Review — ♻️ refactor(di): pre-instantiate DI providers and clean up projectOverall Assessment: Request Changes (minor items)The core refactoring idea is solid — removing the 🔴 Critical Issues1. The new file mixes absolute and relative imports: from src.infrastructure.i18n import I18nProvider # absolute
from .auth import AuthProvider # relative
from .db import DBProvider # relativeEvery other provider is imported from a sibling submodule via relative import. 2. docsThis silently ignores any file or directory named docs/plans/🟡 Suggestions3. Shared provider instances — document the assumption
Current providers appear stateless in # Providers are stateless in __init__; instances are shared across containers.
infra_providers = [...]4. Noisy commit history The PR contains a commit-revert-re-fix sequence for the credential sync:
Consider squashing these three commits before merge — the intermediate state is broken (credential mismatch) and adds noise to 5.
6. The new "deny": ["Write(*lock*)"]This will block any agent attempt to update ✅ What's Good
Bottom line: Fix the |
Pull Request
Description
Centralize Dishka provider instantiation in the DI module instead of duplicating it at each usage site (API app, bot, tests). Also removes outdated plan documents and updates project config.
Type of Change
Changes
DI Provider Refactor
infra_providersandinteractor_providersare now lists of instances instead of classes[interactor() for interactor in interactor_providers]pattern fromapp.py,bot/main.py, andtests/integration/conftest.pyI18nProvider()andDBProvider()intoinfra_providerslist__all__exports to only exposeinfra_providersandinteractor_providersCleanup
docs/plans/.gitignore(added*.omc,docs)config-local.yamltest DB credentials.claude/settings.local.jsonpermissionsTesting
Code Quality
pre-commit run --all-files)ruff check src/ tests/)ruff format src/ tests/ --check)Additional Notes
The test conftest still instantiates
AuthProvider()andDBProvider(worker_postgres_config)directly since it needs a worker-specific postgres config override.🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com