tessl install tessl/pypi-rodi@2.0.0Implementation of dependency injection for Python 3
Agent Success
Agent success rate when using this tile
92%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.06x
Baseline
Agent success rate without this tile
87%
A system for managing application configuration with dependency injection that properly handles class-level settings and instance-level dependencies.
Build a ConfigService class that:
ClassVarLogger instance through dependency injectionBuild a DatabaseManager class that:
ClassVarConfigService and Logger through dependency injectionBuild a RequestHandler class that:
DatabaseManager instance through dependency injection@generates
from typing import ClassVar
from rodi import Container
class Logger:
"""Simple logger for demonstration."""
def log(self, message: str) -> None:
"""Log a message."""
pass
class ConfigService:
"""Manages application configuration with proper separation of class-level and instance-level data."""
# Class-level configuration that should NOT be injected
app_config: ClassVar[dict] = {"app_name": "MyApp", "version": "1.0"}
default_timeout: int = 30
max_retries: int = 3
# Instance dependency that SHOULD be injected
logger: Logger
def get_config(self, key: str) -> str:
"""Retrieve configuration value."""
pass
def get_timeout(self) -> int:
"""Get the timeout value."""
pass
class DatabaseManager:
"""Manages database connections with proper class-level configuration."""
# Class-level pool configuration that should NOT be injected
max_pool_size: ClassVar[int] = 10
connection_timeout: int = 60
# Instance dependencies that SHOULD be injected
config: ConfigService
logger: Logger
def connect(self) -> str:
"""Establish database connection."""
pass
class RequestHandler:
"""Handles requests with rate limiting configuration."""
# Class-level settings with defaults that should NOT be injected
rate_limit: int = 100
time_window: int = 60
# Instance dependency that SHOULD be injected
db: DatabaseManager
def handle_request(self) -> str:
"""Process a request."""
pass
def setup_container() -> Container:
"""Configure and return a DI container with all services registered."""
passProvides dependency injection support with intelligent filtering of class variables and initialized attributes.
@satisfied-by