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

Plugin System with Interchangeable DI Containers

Build a plugin management system that supports multiple dependency injection container implementations through a common interface.

Problem

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.

Requirements

Container Wrapper

Create a ContainerWrapper class that:

  • Accepts any container that implements the required protocol (has register, resolve, and __contains__ methods)
  • Provides a consistent interface for plugin registration regardless of the underlying container implementation
  • Validates that the container supports the necessary operations

Plugin Interface

Each plugin should:

  • Define a register_services method that accepts a container instance
  • Register its services using only the protocol methods: register(), resolve(), and __contains__
  • Not depend on any specific container implementation

Plugin Manager

Create a PluginManager class that:

  • Takes a container wrapper in its constructor
  • Provides a load_plugin method that calls the plugin's register_services method
  • Provides a get_service method that resolves services from the underlying container

Test Cases

  • A plugin successfully registers a service and retrieves it through the manager @test
  • The system works with the rodi Container implementation @test
  • The system works with a custom container implementation that follows the protocol @test
  • The ContainerWrapper validates that the container has required methods @test

Implementation

@generates

API

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."""
        ...

Dependencies { .dependencies }

rodi { .dependency }

Python dependency injection library for container implementation.

@satisfied-by