narokishi/lightweight-di

Lightweight dependency injection with lazy load for PHP applications

v1.0.1 2020-05-19 17:48 UTC

This package is auto-updated.

Last update: 2024-09-20 03:08:09 UTC


README

Description

"Lightweight Dependency Injection" is a PHP package, which allows to inject your dependencies within services. It builds only required classes for the current request.

Installation

Composer

Installing via Composer will keep this package up to date for you.

composer require narokishi/lightweight-di

Usage

use Narokishi\DependencyInjection\Container;

...

$container = new Container;
$container->registerService(ExampleService::class, function () {
    return new ExampleService(
        ...constructorArgs
    );
});
$container->registerService(SecondExampleService::class, function (Container $container) {
    return new SecondExampleService(
        $container->getService(ExampleService::class)
    );
});

...

$secondExampleService = $container->getService(SecondExampleService::class);

Contributing

Thank you for considering contributing to the package.