Skip to content

feat: provide settings to the database engine through the container - #67

Merged
lesnik512 merged 1 commit into
mainfrom
feat/settings-in-container
Oct 19, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
feat/settings-in-container

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Brings chat-app in line with modern-python/litestar-sqlalchemy-template#81 and modern-python/fastapi-sqlalchemy-template#104: the database engine gets its settings from the container instead of the module-level settings.

Changes

  • ioc.Config.settings is a cached Factory(Settings).
  • create_database_engine(settings: Settings) is autowired by type, the same way database_session already gets its engine.
  • New test: a fresh container with Config.settings overridden builds an engine with the overridden pool size.
  • Tests that build an engine by hand pass the module-level settings explicitly.
  • AGENTS.md lists the Config group and says which code still reads the global.

Design notes

  • There is one engine, so there is no derive here. It only helps when components need different values from the same settings. No modern-di bump is needed.
  • app/api/auth.py builds jwt_cookie_auth at import time, before any container exists, so it keeps reading the global, as do __main__, migrations/env.py and build_app.

Testing

just test: 155 passed, 100% coverage. ruff and ty are clean.

The engine takes Settings from ioc.Config.settings, so a test can
override settings instead of relying on the module-level instance.
@lesnik512
lesnik512 merged commit e2031fc into main Oct 19, 2026
4 checks passed
@lesnik512
lesnik512 deleted the feat/settings-in-container branch October 19, 2026 16:23
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