or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/rodi@2.0.x
tile.json

tessl/pypi-rodi

tessl install tessl/pypi-rodi@2.0.0

Implementation 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%

task.mdevals/scenario-10/

Configuration Management System

A system for managing application configuration with dependency injection that properly handles class-level settings and instance-level dependencies.

Capabilities

Configuration Service with Class Variables

Build a ConfigService class that:

  • Has a class-level configuration dictionary stored as a ClassVar
  • Has default timeout and retry values as class attributes with initial values
  • Receives a Logger instance through dependency injection
  • The class variables and initialized attributes should NOT be overridden by the DI container

Database Connection Manager

Build a DatabaseManager class that:

  • Has a class-level connection pool size limit as a ClassVar
  • Has a default connection timeout with an initialized value
  • Receives both a ConfigService and Logger through dependency injection
  • Only the dependencies should be injected, not the class configuration

Request Handler

Build a RequestHandler class that:

  • Has class-level rate limit settings as class attributes with default values
  • Receives a DatabaseManager instance through dependency injection
  • The rate limit configuration should remain as class-level defaults

Implementation

@generates

API

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."""
    pass

Test Cases

  • The ConfigService receives an injected Logger but retains its ClassVar app_config and initialized default_timeout and max_retries values @test
  • The DatabaseManager receives injected ConfigService and Logger but retains its ClassVar max_pool_size and initialized connection_timeout @test
  • The RequestHandler receives an injected DatabaseManager but retains its initialized rate_limit and time_window values @test
  • All services can be resolved from the container and form a complete dependency chain @test

Dependencies { .dependencies }

rodi { .dependency }

Provides dependency injection support with intelligent filtering of class variables and initialized attributes.

@satisfied-by