narokishi / lightweight-di
轻量级依赖注入,适用于PHP应用,支持懒加载
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: 2024-09-20 03:08:09 UTC
README
描述
"轻量级依赖注入" 是一个 PHP 包,允许在服务中注入依赖项。它只为当前请求构建所需的类。
安装
Composer
通过 Composer 安装将为您保持此包的更新。
composer require narokishi/lightweight-di
使用方法
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);
贡献
感谢您考虑为该包做出贡献。