PHPackages                             midnight/automatic-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. [Framework](/categories/framework)
4. /
5. midnight/automatic-di

ActiveLibrary[Framework](/categories/framework)

midnight/automatic-di
=====================

automatic dependency injection for PHP

1.2.0(5y ago)024.3k↑89.6%1[1 PRs](https://github.com/MidnightDesign/automatic-di/pulls)1MITPHPPHP ^7.4 || ^8.0CI failing

Since Sep 13Pushed 4y ago1 watchersCompare

[ Source](https://github.com/MidnightDesign/automatic-di)[ Packagist](https://packagist.org/packages/midnight/automatic-di)[ RSS](/packages/midnight-automatic-di/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (9)Versions (6)Used By (1)

midnight/automatic-di
=====================

[](#midnightautomatic-di)

[![Build Status](https://camo.githubusercontent.com/801bb1384792379944439d6b1d24dbfbb5c3499ee9b6ea6c386ba7d33254ac3d/68747470733a2f2f7472617669732d63692e6f72672f4d69646e6967687444657369676e2f6175746f6d617469632d64692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/MidnightDesign/automatic-di)

This package provides automatic dependency injection for PHP. It requires a [container-interop](https://github.com/container-interop/container-interop)-compatible container.

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

[](#installation)

Composer: [midnight/automatic-di](https://packagist.org/packages/midnight/automatic-di)

Usage
-----

[](#usage)

Let's say we have the following interfaces and classes:

```
interface FooInterface {
}

class Foo {
    private $bar;
    public function __construct(Bar $bar) {
        $this->bar = $bar;
    }
}

class Bar {
}

interface BazInterface {
}

class Baz {
}

class Hodor {
    private $baz;
    public function __construct(BazInterface $baz) {
        $this->baz = $baz;
    }
}
```

Now we can use the `AutomaticDiContainer` like this:

```
$wrappedContainer = new Some\Other\Container; // An implementation of Interop\Container\ContainerInterface
$config = Midnight\AutomaticDi\AutomaticDiConfig::fromArray([
    'preferences' => [
        FooInterface::class => Foo::class,
    ],
    'classes' => [
        Hodor::class => [
            'baz' => Baz::class,
        ],
    ],
]);
$container = new Midnight\AutomaticDi\AutomaticDiContainer($wrappedContainer, $config);

$foo = $container->get(FooInterface::class); // Returns an instance of Foo
$hodor = $container->get(Hodor::class); // Returns an instance of Hodor with an injected Baz
```

Performance
-----------

[](#performance)

> This package works via reflection. Isn't that slow?

Yes, it is. A cache is coming soon.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% 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 ~834 days

Total

3

Last Release

1912d ago

PHP version history (3 changes)v1.0.0PHP ^7.0

1.1.0PHP ^7.4

1.2.0PHP ^7.4 || ^8.0

### Community

Maintainers

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

---

Top Contributors

[![MidnightDesign](https://avatars.githubusercontent.com/u/743172?v=4)](https://github.com/MidnightDesign "MidnightDesign (6 commits)")[![rieschl](https://avatars.githubusercontent.com/u/3321556?v=4)](https://github.com/rieschl "rieschl (3 commits)")

---

Tags

container-interopdependency-injectionphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[symfony/symfony

The Symfony PHP framework

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

The CakePHP framework

8.9k19.5M1.8k](/packages/cakephp-cakephp)[bref/bref

Bref is a framework to write and deploy serverless PHP applications on AWS Lambda.

3.4k10.6M67](/packages/bref-bref)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)

PHPackages © 2026

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