Skip to content

fix: add circular dependency detection at build time#5

Merged
hartym merged 2 commits into
mainfrom
fix/circular-dependency-detection
Feb 5, 2026
Merged

fix: add circular dependency detection at build time#5
hartym merged 2 commits into
mainfrom
fix/circular-dependency-detection

Conversation

@hartym
Copy link
Copy Markdown
Contributor

@hartym hartym commented Feb 5, 2026

Summary

  • Add circular dependency detection during ContainerBuilder.build() using DFS
  • Raises CircularDependencyError with full cycle path (e.g., "A → B → C → A")
  • Fix documentation to use correct async API (await, async with)
  • Add documentation for lifecycle hooks and autowire parameter

Fixes #1

Changes

Circular Dependency Detection

  • Implement DFS-based cycle detection in _check_circular_dependencies()
  • Detect direct cycles (A → B → A), indirect cycles (A → B → C → A), and self-references
  • Correctly allow diamond patterns (shared dependencies)
  • Works regardless of scope configuration (singleton, scoped, transient)

Documentation Fixes

  • Add pre-alpha warning to documentation index
  • Fix all code examples to use await container.get() and async with container.scope()
  • Document initializer, finalizer, and autowire parameters
  • Remove references to non-existent exceptions
  • Fix toctree order to follow Diátaxis framework

Test Plan

  • All 113 tests pass
  • New tests for cycle detection (direct, indirect, self-reference, diamond pattern)
  • Documentation builds without errors
  • Linting and type checking pass

Detect cycles in the dependency graph during ContainerBuilder.build()
using depth-first search. Raises CircularDependencyError with the full
cycle path (e.g., "A → B → C → A") for easy debugging.

Handles direct cycles (A → B → A), indirect cycles (A → B → C → A),
self-references (A → A), and correctly allows diamond patterns.
- Add pre-alpha warning to documentation index
- Fix all code examples to use async/await and async context managers
- Add documentation for lifecycle hooks (initializer, finalizer)
- Add documentation for autowire parameter
- Remove references to non-existent exceptions (TypeResolutionError,
  InstantiationError)
- Fix toctree order to follow Diátaxis (tutorials, how-to, explanation,
  reference)
- Update error handling section to reflect actual exceptions
@hartym hartym merged commit 36d4cd8 into main Feb 5, 2026
12 checks passed
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.

bug: missing circular dependency detection causes stack overflow vulnerability

1 participant