Skip to content

Make resolve_dependencies async with dual sync/async factory support #29

@DaviddeBest-TNO

Description

@DaviddeBest-TNO

Parent

#27

What to build

Make the dependency injection resolver async-aware so that Depends factories can be either def or async def.

Resolver: resolve_dependencies() becomes async def. For each Depends factory, detect whether it is a coroutine function via asyncio.iscoroutinefunction(). Async factories are awaited directly; sync factories are called directly (no to_thread — factories are typically fast initializers). Caching semantics are unchanged: cache=True factories are called at most once per invocation, cache=False factories are called fresh each time.

Transitive resolution: The recursive call to resolve a factory's own dependencies must also be awaited, since nested factories may themselves be async.

Overrides: dependency_overrides behavior is unchanged — an override factory replaces the original and may itself be sync or async independently of the original.

Acceptance criteria

  • resolve_dependencies() is async def
  • Async Depends factories (async def) are detected and awaited
  • Sync Depends factories (def) continue to work without changes
  • Nested/transitive resolution works when mixing sync and async factories
  • dependency_overrides works with async replacement factories
  • Caching semantics (cache=True/False) preserved for both sync and async factories
  • All DI tests updated to async and passing
  • uv run ruff check . passes

Blocked by

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestready-for-agentIssue is ready for agent implementation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions