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 event handling system that uses dependency injection to execute event handlers with their required dependencies automatically injected.
Create a system that:
Your implementation should consist of:
EventManager class that manages and dispatches events to registered handlers@generates
from typing import Callable, Any, TypeVar
T = TypeVar('T')
class EventManager:
"""Manages event handlers with dependency injection."""
def __init__(self, provider):
"""
Initialize the event manager with a service provider.
Args:
provider: A rodi Services instance that provides dependency resolution
"""
pass
def register_handler(self, event_type: str, handler: Callable[..., T]) -> None:
"""
Register a handler function for a specific event type.
Args:
event_type: The name/type of the event
handler: A function that will be called when the event is triggered.
Dependencies will be automatically injected based on type hints.
"""
pass
def trigger_event(self, event_type: str) -> Any:
"""
Trigger an event and execute its registered handler with dependency injection.
Args:
event_type: The name/type of the event to trigger
Returns:
The result returned by the handler function
Raises:
ValueError: If no handler is registered for the event type
"""
passProvides dependency injection functionality for executing functions with auto-injected parameters.
@satisfied-by