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

User Service Manager

Build a simple user service manager that handles user data retrieval and email notification services using dependency injection.

Requirements

Create a system with the following components:

  1. A UserRepository class that stores and retrieves user data
  2. An EmailService class that sends email notifications
  3. A UserManager class that uses both services to manage user operations

The system should:

  • Register all services in a dependency injection container
  • Build a service provider from the container
  • Resolve the UserManager service from the provider
  • Use the manager to retrieve a user and send them an email notification

Implementation Details

UserRepository

  • Should have a method get_user(user_id: int) that returns a dictionary with user info
  • For testing purposes, return {"id": user_id, "name": f"User{user_id}", "email": f"user{user_id}@example.com"}

EmailService

  • Should have a method send_email(recipient: str, subject: str, body: str) that returns a success message
  • For testing purposes, return f"Email sent to {recipient}: {subject}"

UserManager

  • Should accept both UserRepository and EmailService as dependencies via constructor
  • Should have a method notify_user(user_id: int) that:
    • Retrieves the user from the repository
    • Sends them an email with subject "Hello" and body "Welcome message"
    • Returns the email service response

Test Cases

  • When UserManager is resolved from the provider and notify_user(42) is called, it returns "Email sent to user42@example.com: Hello" @test
  • When checking if UserManager is available in the provider using the in operator, it returns True @test
  • When resolving UserRepository directly from the provider, it returns a valid UserRepository instance @test

Implementation

@generates

API

class UserRepository:
    """Repository for managing user data."""

    def get_user(self, user_id: int) -> dict:
        """Retrieve user information by ID."""
        pass

class EmailService:
    """Service for sending email notifications."""

    def send_email(self, recipient: str, subject: str, body: str) -> str:
        """Send an email and return a confirmation message."""
        pass

class UserManager:
    """Manager that coordinates user operations."""

    def __init__(self, repository: UserRepository, email_service: EmailService):
        """Initialize with required services."""
        pass

    def notify_user(self, user_id: int) -> str:
        """Retrieve user and send them a notification email."""
        pass

def create_service_provider():
    """Create and return a configured service provider."""
    pass

Dependencies { .dependencies }

rodi { .dependency }

Provides dependency injection support for managing services.

@satisfied-by