narokishi / lightweight-di
Lightweight dependency injection with lazy load for PHP applications
v1.0.1
2020-05-19 17:48 UTC
Requires
- php: >=7.1.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^7.3.2
This package is auto-updated.
Last update: 2025-04-20 04:17:50 UTC
README
Build | Coverage | Downloads | Release | License |
---|---|---|---|---|
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.