Skip to content

feat(service): add service composition primitives#722

Draft
cofin wants to merge 1 commit into
feat/service-composition-utility-extractionfrom
feat/service-composition-core-composition
Draft

feat(service): add service composition primitives#722
cofin wants to merge 1 commit into
feat/service-composition-utility-extractionfrom
feat/service-composition-core-composition

Conversation

@cofin

@cofin cofin commented Apr 26, 2026

Copy link
Copy Markdown
Member

Summary

  • Add ServiceComposition[Unpack[Ts]] for typed async service composition on a caller-owned session
  • Add public ServiceProvider and ServiceWithSession typing primitives
  • Re-export the new service composition API from advanced_alchemy.service
  • Add runtime and typing tests for provider cleanup and per-position variadic typing

Stack

Notes

  • composition.py uses a local async-generator closing helper because Python 3.9 lacks contextlib.aclosing; it can be refactored to contextlib.aclosing once 3.9 support is dropped.
  • No unasyncd mapping was added because the current config enumerates only _async.py sources; composition.py is intentionally async-only and is not picked up.
  • The intended app workflow remains the fullstack SPA shape: keep normal singular create_service_provider(...) providers, then compose those existing providers with async with provide_services(...) in listeners/jobs/CLI/guards. Ch.3 will add the Litestar wrapper for that path.

Validation

  • .venv/bin/pytest tests/unit/test_utils/test_dependencies.py tests/unit/test_extensions/test_litestar/test_providers_wire_compat.py tests/unit/test_extensions/test_litestar/test_providers.py tests/unit/test_extensions/test_fastapi/test_providers.py tests/unit/test_service -q
  • .venv/bin/ruff check advanced_alchemy/utils/dependencies.py advanced_alchemy/extensions/litestar/providers.py advanced_alchemy/extensions/fastapi/providers.py advanced_alchemy/service/composition.py advanced_alchemy/service/_typing.py tests/unit/test_utils/test_dependencies.py tests/unit/test_extensions/test_litestar/test_providers_wire_compat.py tests/unit/test_extensions/test_litestar/test_providers.py tests/unit/test_extensions/test_fastapi/test_providers.py tests/unit/test_service/test_composition.py tests/unit/test_service/test_composition_typing.py
  • .venv/bin/mypy advanced_alchemy/utils/dependencies.py advanced_alchemy/extensions/litestar/providers.py advanced_alchemy/extensions/fastapi/providers.py advanced_alchemy/service/composition.py advanced_alchemy/service/_typing.py tests/unit/test_utils/test_dependencies.py tests/unit/test_extensions/test_litestar/test_providers_wire_compat.py tests/unit/test_extensions/test_fastapi/test_providers.py tests/unit/test_service/test_composition.py tests/unit/test_service/test_composition_typing.py
  • .venv/bin/pyright advanced_alchemy/utils/dependencies.py advanced_alchemy/extensions/litestar/providers.py advanced_alchemy/extensions/fastapi/providers.py advanced_alchemy/service/composition.py advanced_alchemy/service/_typing.py tests/unit/test_utils/test_dependencies.py tests/unit/test_extensions/test_litestar/test_providers_wire_compat.py tests/unit/test_extensions/test_fastapi/test_providers.py tests/unit/test_service/test_composition.py tests/unit/test_service/test_composition_typing.py

📚 Documentation preview: https://litestar-org.github.io/advanced-alchemy-docs-preview/722

@cofin
cofin force-pushed the feat/service-composition-core-composition branch from 3cf18d5 to 866b4a9 Compare May 25, 2026 16:03
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant