Small Dependency Injection

Introducing small/dependency-injection

I’ve just released small/dependency-injection — a lightweight, framework-agnostic Dependency Injection container for PHP 8.4.

Quick Start

Install via Composer:

composer require small/d…


This content originally appeared on DEV Community and was authored by sebk69

Introducing small/dependency-injection

I’ve just released small/dependency-injection — a lightweight, framework-agnostic Dependency Injection container for PHP 8.4.

Quick Start

Install via Composer:

composer require small/dependency-injection

Define your container configuration:

<?php

use Small\DependencyInjection\AbstractContainerConfiguration;
use function Small\DependencyInjection\injectService;
use function Small\DependencyInjection\injectParameter;

class AppConfig extends AbstractContainerConfiguration
{
    public function configure(): self
    {
        $this->parameter('secret', 'top-secret')
             ->service(
                 MyServiceInterface::class,
                 MyService::class,
                 [
                     injectParameter('secret'),
                     injectService(LoggerInterface::class),
                 ]
             )
             ->autowireNamespace('App');

        return $this;
    }
}

Use it:

$config = new AppConfig(__DIR__ . '/composer.json');
$config->loadParameters($container);

$myService = $container->get(MyServiceInterface::class);

Links

That’s it — a simple, modern DI container for your next PHP project.


This content originally appeared on DEV Community and was authored by sebk69


Print Share Comment Cite Upload Translate Updates
APA

sebk69 | Sciencx (2025-09-27T19:48:39+00:00) Small Dependency Injection. Retrieved from https://www.scien.cx/2025/09/27/small-dependency-injection/

MLA
" » Small Dependency Injection." sebk69 | Sciencx - Saturday September 27, 2025, https://www.scien.cx/2025/09/27/small-dependency-injection/
HARVARD
sebk69 | Sciencx Saturday September 27, 2025 » Small Dependency Injection., viewed ,<https://www.scien.cx/2025/09/27/small-dependency-injection/>
VANCOUVER
sebk69 | Sciencx - » Small Dependency Injection. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/09/27/small-dependency-injection/
CHICAGO
" » Small Dependency Injection." sebk69 | Sciencx - Accessed . https://www.scien.cx/2025/09/27/small-dependency-injection/
IEEE
" » Small Dependency Injection." sebk69 | Sciencx [Online]. Available: https://www.scien.cx/2025/09/27/small-dependency-injection/. [Accessed: ]
rf:citation
» Small Dependency Injection | sebk69 | Sciencx | https://www.scien.cx/2025/09/27/small-dependency-injection/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.