Property-based dependency injection with interface autowiring, named slots, and shared versus fresh instances for Switon Framework

Maintainers

Package info

github.com/switon-php/di

Documentation

pkg:composer/switon/di

Statistics

Installs: 68

Dependents: 10

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-06 13:43 UTC

This package is auto-updated.

Last update: 2026-06-07 01:45:55 UTC


README

CI PHP 8.3+

Switon's dependency injection container for autowiring, named services, and bootstrap wiring.

Highlights

  • Shared container: ContainerInterface handles 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: FactoryInterface supports multiple implementations of the same type.
  • Lazy dependencies: Lazy defers 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.