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-3/

Configuration Manager with Type-Safe Collections

Overview

Build a configuration management system that loads and provides access to different types of configuration collections. The system should support multiple configuration sources with strong type safety.

Requirements

Implement a configuration management system with the following features:

  1. Configuration Data Classes:

    • Create a DatabaseConfig dataclass with fields: host (str), port (int), name (str)
    • Create an ApiEndpoint dataclass with fields: name (str), url (str), timeout (int)
    • Create a FeatureFlag dataclass with fields: key (str), enabled (bool)
  2. Configuration Providers:

    • Implement a ConfigurationService class that:
      • Accepts a collection of database configurations (multiple DatabaseConfig instances)
      • Accepts a mapping of endpoint names to ApiEndpoint configurations
      • Accepts an optional feature flags collection
      • Provides methods to retrieve configurations by name or key
  3. Application Service:

    • Create an ApplicationBootstrap class that depends on:
      • A list of database configurations
      • A dictionary of API endpoint configurations
      • An optional feature flags list
    • Should initialize and store these collections for application use
  4. Dependency Injection Setup:

    • Configure your dependency injection container to register:
      • A list containing 3 database configurations with different settings
      • A dictionary mapping endpoint names ("auth", "users", "orders") to their configurations
      • An optional list of feature flags (at least 2 flags)
    • Register the ConfigurationService and ApplicationBootstrap classes
    • Resolve and verify that ApplicationBootstrap receives all configurations correctly

Constraints

  • Use factory functions to create the configuration collections
  • All configuration collections must be registered with appropriate return type annotations
  • The ConfigurationService must use type-annotated constructor parameters
  • Test that the same collection instances are shared when appropriate

Dependencies { .dependencies }

rodi { .dependency }

Provides dependency injection support for managing service lifecycles and dependencies.

Test Cases

Test 1: Resolve Configuration Service { .test }

File: test_config.py

# Verify that ConfigurationService can be resolved and receives
# the correct number of database configs (3) and endpoint configs (3)
def test_resolve_configuration_service():
    container = setup_container()
    provider = container.build_provider()

    service = provider.get(ConfigurationService)

    assert service is not None
    assert len(service.database_configs) == 3
    assert len(service.endpoint_configs) == 3

Test 2: Verify Dictionary Configuration { .test }

File: test_config.py

# Verify that the endpoint configurations dictionary has the correct keys
# and contains properly structured ApiEndpoint objects
def test_endpoint_configuration_structure():
    container = setup_container()
    provider = container.build_provider()

    service = provider.get(ConfigurationService)

    assert "auth" in service.endpoint_configs
    assert "users" in service.endpoint_configs
    assert service.endpoint_configs["auth"].url is not None

Test 3: Application Bootstrap Integration { .test }

File: test_config.py

# Verify that ApplicationBootstrap receives all injected collections
# and that optional feature flags are properly injected
def test_application_bootstrap():
    container = setup_container()
    provider = container.build_provider()

    bootstrap = provider.get(ApplicationBootstrap)

    assert bootstrap is not None
    assert bootstrap.databases is not None
    assert bootstrap.endpoints is not None
    assert bootstrap.feature_flags is not None
    assert len(bootstrap.feature_flags) >= 2