CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-rodi

Implementation of dependency injection for Python 3

Overall
score

92%

Overview
Eval results
Files

task.mdevals/scenario-6/

Service Dependency Configuration Validator

Build a service configuration validator that checks if all required services are properly registered in a dependency injection container before the application starts.

Overview

You need to create a validator that reads service dependency requirements from a configuration file and verifies that all necessary services are registered in the DI container. This helps catch missing service registrations early, before runtime errors occur.

Requirements

Configuration File Format

The validator should read a JSON configuration file with the following structure:

{
  "required_services": [
    "DatabaseConnection",
    "Logger",
    "CacheService",
    "EmailService"
  ]
}

Validation Logic

  1. Load the configuration file to get the list of required service names
  2. For each required service, check if it's available in the container
  3. Report which services are missing (if any)
  4. Return a validation result indicating success or failure

Implementation Files

Create the following files:

  • validator.py - Contains the ServiceValidator class
  • validator.test.py - Contains test cases

ServiceValidator Class

The class should have these methods:

  • __init__(self, container) - Initialize with a DI container
  • validate(self, config_path: str) -> dict - Validate services and return a result dictionary

The result dictionary should have this structure:

{
    "valid": bool,           # True if all services are available
    "missing": list[str],    # List of missing service names (empty if all available)
    "checked": int           # Number of services checked
}

Test Cases

  • Given a container with Logger and CacheService registered, and a config requiring Logger, CacheService, and EmailService, the validation returns valid=False with missing=["EmailService"] and checked=3 @test

  • Given a container with all services registered (DatabaseConnection, Logger, CacheService, EmailService), and a config requiring all four, the validation returns valid=True with missing=[] and checked=4 @test

  • Given an empty container and a config requiring DatabaseConnection and Logger, the validation returns valid=False with missing=["DatabaseConnection", "Logger"] and checked=2 @test

Implementation Notes

  • You can represent service types as simple classes for testing purposes
  • The validator should work with any DI container that supports checking service availability
  • Focus on the service availability checking functionality

Dependencies { .dependencies }

rodi { .dependency }

Provides dependency injection container functionality

@generates

Install with Tessl CLI

npx tessl i tessl/pypi-rodi

tile.json