PHPackages                             solophp/container - 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. solophp/container

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

solophp/container
=================

Dependency Injection Container implementing WritableContainerInterface

v2.3.0(2mo ago)01181MITPHPPHP &gt;=8.1

Since Jul 13Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/SoloPHP/Container)[ Packagist](https://packagist.org/packages/solophp/container)[ RSS](/packages/solophp-container/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (8)Versions (7)Used By (1)

Solo PHP Container
==================

[](#solo-php-container)

Lightweight PSR-11 dependency injection container with auto-wiring, interface binding, and singleton caching.

[![Latest Version on Packagist](https://camo.githubusercontent.com/420370aa747a5a5f81e7a3b26cc7ea8b1285783b6dc4249d96e63453c4976d3f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f6c6f7068702f636f6e7461696e65722e737667)](https://packagist.org/packages/solophp/container)[![PHP Version](https://camo.githubusercontent.com/b0b6d5f16e83ecdb2339571189bb6e44a49e79db7b8e5bddf8a9530c7442eb54/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532422d3838393242462e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![Coverage](https://camo.githubusercontent.com/b3545ae1bcdb4ea486f71f87b43001e82dd21933bc8035d44601706c851265da/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e2e737667)](https://github.com/solophp/container)

Features
--------

[](#features)

- **PSR-11 Compatible** — Implements `WritableContainerInterface` from `solophp/contracts`
- **Auto-wiring** — Automatic dependency resolution via constructor reflection
- **Interface Binding** — Bind abstracts to concrete implementations
- **Singleton Caching** — Each service resolved once and cached
- **Cache Invalidation** — `set()` invalidates cached instance, `reset()` clears all
- **Service Factories** — Register services as callable factories

Installation
------------

[](#installation)

```
composer require solophp/container
```

Quick Example
-------------

[](#quick-example)

```
use Solo\Container\Container;

$container = new Container();

// Register a service factory
$container->set(Database::class, fn($c) => new Database('localhost', 'mydb'));

// Bind interface to implementation
$container->bind(LoggerInterface::class, FileLogger::class);

// Resolve with auto-wired dependencies
$repo = $container->get(UserRepository::class);
```

Usage
-----

[](#usage)

### Constructor Registration

[](#constructor-registration)

```
$container = new Container([
    'config' => fn() => new Config('config.php'),
    'cache'  => fn($c) => new Cache($c->get('config')),
]);
```

### Auto-wiring

[](#auto-wiring)

The container automatically resolves class dependencies via constructor reflection:

```
class UserRepository
{
    public function __construct(
        private Database $database,
        private LoggerInterface $logger
    ) {}
}

// Database and LoggerInterface resolved automatically
$repo = $container->get(UserRepository::class);
```

### Interface Binding

[](#interface-binding)

```
$container->bind(LoggerInterface::class, FileLogger::class);
$container->bind(CacheInterface::class, RedisCache::class);
```

### Re-registering Services

[](#re-registering-services)

`set()` invalidates the cached instance, so the next `get()` uses the new factory:

```
$container->set(Connection::class, fn() => new Connection('db1'));
$conn1 = $container->get(Connection::class); // Connection to db1

$container->set(Connection::class, fn() => new Connection('db2'));
$conn2 = $container->get(Connection::class); // Connection to db2
```

### Resetting All Instances

[](#resetting-all-instances)

When a root dependency changes and the entire dependency tree needs rebuilding:

```
$container->reset(); // All cached instances cleared
```

Error Handling
--------------

[](#error-handling)

- `Solo\Container\Exceptions\NotFoundException` — service not found
- `Solo\Container\Exceptions\ContainerException` — service cannot be resolved

Requirements
------------

[](#requirements)

- PHP 8.1+

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance86

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

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

Every ~121 days

Recently: every ~152 days

Total

6

Last Release

66d ago

Major Versions

v1.0.1 → v2.0.02025-08-02

PHP version history (2 changes)v1.0.0PHP &gt;=7.4

v2.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/2f29817cec408d033cd4441c8f760e3ae40248dc0f66856a09080d282aee6959?d=identicon)[Vitaliy Olos](/maintainers/Vitaliy%20Olos)

---

Top Contributors

[![SoloPHP](https://avatars.githubusercontent.com/u/175482616?v=4)](https://github.com/SoloPHP "SoloPHP (11 commits)")

---

Tags

phpcontainerPSR-11di

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/solophp-container/health.svg)

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

###  Alternatives

[devanych/di-container

Simple implementation of a PSR-11 dependency injection container

124.2k3](/packages/devanych-di-container)

PHPackages © 2026

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