How reagento/dishka works
Project Type and Purpose
• Dishka is a standalone DI framework for Python. Its goal is to manage object lifecycles, resolve dependencies via providers, and integrate seamlessly with several popular frameworks.
• The README emphasizes key features like scopes, finalization, modular providers, and integrations. The purpose is to offer clean, fast, and modular dependency injection to avoid boilerplate like global variables or manual dependency passing.
Core Components
a. DI Container:
• Central container that manages dependency lifecycles and caching.
• Elements like the container’s ability to enter and exit different scopes (APP, REQUEST, etc.).
b. Providers:
• That providers can be functions, classes, or methods (using the @provide decorator) and can also manage “finalization” (object release).
c. Dependency Entities:
• Objects described by type hints, including components like Service, DAO, and various other dependency markers.
• How “entities” (e.g. depends_marker, provides_marker) play a role in the resolution process.
d. Scopes:
• How different scopes (APP, REQUEST, etc.) are managed for object lifetimes.
e. Framework Integrations:
• Out the integration modules (for example, for fastapi, flask, aiogram, aiohttp, grpcio, etc.) to show Dishka’s extensibility.
• Each integration module interfaces with the DI container, allowing DI to easily plug into external systems.
f. Plotter and Visualization:
g. Testing & Examples:
Relationships and Data Flows
• Document the role of “Scopes” by showing that the container’s operation is filtered by the scope lifecycle (entering/exiting contexts tied to APP, REQUEST, etc.).
• Integrations as distinct external modules or blocks that communicate with the core container, receiving dependencies through decorators or direct lookups.
Architectural Patterns and Design Principles
• Use of inversion of control (IoC) – where object creation is decoupled from business logic.
• Modularity: Providers are independent and can be composed into components, as well as integration modules being individually pluggable.
• Design principle of “scoping” for dependency lifetimes to control caching and finalization.
Technologies, Frameworks, and Libraries
• Python artifacts like type hints, decorators, and protocols fed into the dependency resolution.
• That Dishka is built around pure Python constructs but offers integrations with many frameworks (like FastAPI, Flask, gRPC, etc.), which are clearly visible in the integrations directories.