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 user profile management system with dependency injection for data access and email notification services.
Implement a system with the following components:
Database Context - A class that simulates database connection and provides methods to fetch and save user data. It should have:
get_user(user_id: int) method that returns a dictionary with user data (id, name, email)save_user(user_data: dict) method that persists user dataEmail Service - A class that handles email notifications. It should have:
send_email(recipient: str, subject: str, body: str) method that simulates sending an emailUser Repository - A class that uses the database context to perform user-related data operations. It should:
find_user_by_id(user_id: int) methodupdate_user(user_id: int, name: str, email: str) methodUser Profile Service - A class that coordinates user profile operations. It should:
get_profile(user_id: int) method that retrieves user informationupdate_profile(user_id: int, name: str, email: str) method that updates user data and sends a confirmation emailDependency Injection Setup - Configure the system to:
@generates
class DatabaseContext:
"""Simulates database connection and operations."""
def get_user(self, user_id: int) -> dict:
"""Retrieve user data by ID."""
pass
def save_user(self, user_data: dict) -> None:
"""Save user data."""
pass
class EmailService:
"""Handles email notifications."""
def send_email(self, recipient: str, subject: str, body: str) -> None:
"""Send an email to the recipient."""
pass
class UserRepository:
"""Manages user data access."""
def __init__(self, context: DatabaseContext):
"""Initialize with database context."""
pass
def find_user_by_id(self, user_id: int) -> dict:
"""Find and return user by ID."""
pass
def update_user(self, user_id: int, name: str, email: str) -> None:
"""Update user information."""
pass
class UserProfileService:
"""Coordinates user profile operations."""
def __init__(self, repository: UserRepository, email_service: EmailService):
"""Initialize with repository and email service."""
pass
def get_profile(self, user_id: int) -> dict:
"""Retrieve user profile."""
pass
def update_profile(self, user_id: int, name: str, email: str) -> None:
"""Update user profile and send confirmation email."""
pass
def setup_dependency_injection():
"""Configure and return a service provider with all dependencies registered."""
passProvides dependency injection support.