PHPackages                             switon/di - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. switon/di

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

switon/di
=========

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

v1.0.0(1mo ago)06910MITPHPPHP &gt;=8.3CI passing

Since Jun 6Pushed 1mo agoCompare

[ Source](https://github.com/switon-php/di)[ Packagist](https://packagist.org/packages/switon/di)[ Docs](https://github.com/switon-php/di)[ RSS](/packages/switon-di/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (6)Versions (2)Used By (10)

Switon DI Package
=================

[](#switon-di-package)

[![CI](https://camo.githubusercontent.com/7521191f8d6b6b86615b719d7bae58f34c4a5a77491a973a942c7e7b05fa1527/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f737769746f6e2d7068702f64692f63692e796d6c3f6272616e63683d6d61696e266c6162656c3d4349)](https://github.com/switon-php/di/actions/workflows/ci.yml) [![PHP 8.3+](https://camo.githubusercontent.com/c03f51341eebaefabbf137e291b20523fc74b4ffd084406d88524d266d95085d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d373737424234)](https://www.php.net/)

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

Highlights
----------

[](#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
------------

[](#installation)

```
composer require switon/di
```

Quick Start
-----------

[](#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:

License
-------

[](#license)

MIT.

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance90

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

48d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dc0f20ad15b0ae9fbf9c6e2cd3008692b0c88a877ec8d3e0119211314bf86fc8?d=identicon)[switon](/maintainers/switon)

---

Top Contributors

[![switon-php](https://avatars.githubusercontent.com/u/247358032?v=4)](https://github.com/switon-php "switon-php (1 commits)")

---

Tags

autowiredautowiringcontainerdependency-injectionswitoncontainerAutowiringdependency-injectionswiton

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/switon-di/health.svg)

```
[![Health](https://phpackages.com/badges/switon-di/health.svg)](https://phpackages.com/packages/switon-di)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[testo/testo

A lightweight PHP testing framework.

1959.3k116](/packages/testo-testo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
