switon/di
Composer 安装命令:
composer require switon/di
包简介
Property-based dependency injection with interface autowiring, named slots, and shared versus fresh instances for Switon Framework
README 文档
README
Switon's dependency injection container for autowiring, named services, and bootstrap wiring.
Highlights
- Shared container:
ContainerInterfacehandles service resolution and definition registration. - Service autowiring:
#[Autowired]can inject object services without manual lookups. - Config autowiring: the same attribute can fill scalar and array properties from config.
- Named instances:
FactoryInterfacesupports multiple implementations of the same type. - Lazy dependencies:
Lazydefers non-default resolution until a value is actually used. - Autowired instances:
#[Autowired(instances: true)]can inject service arrays from config.
Installation
composer require switon/di
Quick Start
# switon.yml Switon\Core\AppInterface: id: admin name: Admin Panel version: 2.0.0 env: dev debug: true timezone: Asia/Shanghai
use Switon\Core\AppInterface; use Switon\Core\Attribute\Autowired; class DashboardService { #[Autowired] protected AppInterface $app; public function title(): string { return $this->app->name() . ' (' . $this->app->env() . ')'; } }
Docs: https://docs.switon.dev/latest/di
License
MIT.
统计信息
- 总下载量: 69
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 10
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-07