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

Application Configuration Manager { .spec }

Build a simple configuration management system that maintains shared application settings throughout the application's lifetime. The system should ensure that configuration objects are created only once and reused across all components that need them.

Requirements { .requirements }

Implement a configuration management system with the following components:

  1. AppConfig class: A simple configuration holder with the following attributes:

    • app_name: string representing the application name
    • version: string representing the version number
    • debug_mode: boolean flag for debug mode

    The class should be initialized with these three parameters.

  2. DatabaseConfig class: A configuration holder for database settings with:

    • host: string for database host
    • port: integer for database port
    • database_name: string for the database name

    The class should be initialized with these three parameters.

  3. Application class: A class that uses AppConfig. It should:

    • Accept an AppConfig instance through its initialization
    • Have a method get_app_info() that returns a string in the format: "{app_name} v{version} (debug: {debug_mode})"
  4. DatabaseConnection class: A class that uses DatabaseConfig. It should:

    • Accept a DatabaseConfig instance through its initialization
    • Have a method get_connection_string() that returns a string in the format: "{host}:{port}/{database_name}"
  5. Service registration and resolution:

    • Register AppConfig and DatabaseConfig instances so they are created once and shared
    • Register Application and DatabaseConnection classes
    • Resolve instances of Application and DatabaseConnection
    • Verify that the same configuration instances are used across multiple resolutions

Dependencies { .dependencies }

rodi { .dependency }

Provides dependency injection capabilities for Python applications.

Constraints { .constraints }

  • The configuration instances (AppConfig and DatabaseConfig) must be created exactly once and shared across all components
  • Do not hardcode configuration values in the Application or DatabaseConnection classes
  • Use the dependency injection system to wire up all dependencies

Test Cases { .tests }

Test 1: Configuration sharing { .test @test }

File: test_config_manager.py

Create the following setup:

  • AppConfig with app_name="MyApp", version="1.0.0", debug_mode=True
  • DatabaseConfig with host="localhost", port=5432, database_name="mydb"

Register both configuration instances as shared singletons, then register Application and DatabaseConnection classes. Resolve Application twice and verify:

  • First Application instance's get_app_info() returns "MyApp v1.0.0 (debug: True)"
  • Second Application instance's get_app_info() returns "MyApp v1.0.0 (debug: True)"
  • Both Application instances use the same AppConfig instance (verify with is operator)

Test 2: Multiple service resolution { .test @test }

File: test_config_manager.py

Using the same configuration from Test 1, resolve DatabaseConnection twice and verify:

  • First DatabaseConnection's get_connection_string() returns "localhost:5432/mydb"
  • Second DatabaseConnection's get_connection_string() returns "localhost:5432/mydb"
  • Both DatabaseConnection instances use the same DatabaseConfig instance (verify with is operator)

Test 3: Cross-component configuration sharing { .test @test }

File: test_config_manager.py

Using the same setup, resolve both Application and DatabaseConnection, then:

  • Modify the AppConfig instance's debug_mode to False
  • Resolve a new Application instance
  • Verify the new Application's get_app_info() returns "MyApp v1.0.0 (debug: False)"
  • This confirms the same configuration instance is being shared

Deliverables { .deliverables }

  1. config_manager.py: Contains AppConfig, DatabaseConfig, Application, and DatabaseConnection classes
  2. test_config_manager.py: Contains all test cases