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%
Build a simple user service manager that handles user data retrieval and email notification services using dependency injection.
Create a system with the following components:
UserRepository class that stores and retrieves user dataEmailService class that sends email notificationsUserManager class that uses both services to manage user operationsThe system should:
UserManager service from the providerget_user(user_id: int) that returns a dictionary with user info{"id": user_id, "name": f"User{user_id}", "email": f"user{user_id}@example.com"}send_email(recipient: str, subject: str, body: str) that returns a success messagef"Email sent to {recipient}: {subject}"UserRepository and EmailService as dependencies via constructornotify_user(user_id: int) that:
UserManager is resolved from the provider and notify_user(42) is called, it returns "Email sent to user42@example.com: Hello" @testUserManager is available in the provider using the in operator, it returns True @testUserRepository directly from the provider, it returns a valid UserRepository instance @test@generates
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."""
passProvides dependency injection support for managing services.
@satisfied-by