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 plugin management system that supports multiple dependency injection container implementations through a common interface.
You need to create a plugin system where plugins can be loaded dynamically and their services registered with any DI container implementation that follows a common protocol. The system should support switching between different container implementations without changing plugin code.
Create a ContainerWrapper class that:
register, resolve, and __contains__ methods)Each plugin should:
register_services method that accepts a container instanceregister(), resolve(), and __contains__Create a PluginManager class that:
load_plugin method that calls the plugin's register_services methodget_service method that resolves services from the underlying container@generates
from typing import Protocol, Any, Type
class ContainerProtocol(Protocol):
"""Protocol defining the minimal interface for a DI container."""
def register(self, base_type: Type, concrete_type: Type = None) -> None:
"""Register a service type with the container."""
...
def resolve(self, service_type: Type) -> Any:
"""Resolve and return an instance of the service type."""
...
def __contains__(self, service_type: Type) -> bool:
"""Check if a service type is registered."""
...
class ContainerWrapper:
"""Wraps any container that follows ContainerProtocol."""
def __init__(self, container: ContainerProtocol) -> None:
"""Initialize with a container that implements the protocol."""
...
def register(self, base_type: Type, concrete_type: Type = None) -> None:
"""Register a service type."""
...
def resolve(self, service_type: Type) -> Any:
"""Resolve a service type."""
...
def has_service(self, service_type: Type) -> bool:
"""Check if service is registered."""
...
class Plugin(Protocol):
"""Protocol for plugins that can register services."""
def register_services(self, container: ContainerProtocol) -> None:
"""Register plugin services with the container."""
...
class PluginManager:
"""Manages plugins and their service registration."""
def __init__(self, container_wrapper: ContainerWrapper) -> None:
"""Initialize with a container wrapper."""
...
def load_plugin(self, plugin: Plugin) -> None:
"""Load a plugin by calling its register_services method."""
...
def get_service(self, service_type: Type) -> Any:
"""Get a service from the underlying container."""
...Python dependency injection library for container implementation.
@satisfied-by