PHPackages                             mdarc/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. mdarc/di

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

mdarc/di
========

A simple yet powerful PSR-11 autowiring dependency injection container

v1.0.4(6y ago)14.1kMITPHPPHP &gt;=7.1.0CI failing

Since Sep 18Pushed 6y ago2 watchersCompare

[ Source](https://github.com/mdarc/DI)[ Packagist](https://packagist.org/packages/mdarc/di)[ Docs](https://github.com/mdarc/DI)[ RSS](/packages/mdarc-di/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (4)Dependencies (5)Versions (6)Used By (0)

mdarc/DI
========

[](#mdarcdi)

A simple yet powerful [PSR-11](https://www.php-fig.org/psr/psr-11/) autowiring dependency injection container.

**mdarc/DI** was conceived to be simple to configure and use. It was built for performance. (check [benchmarks](tests/Benchmarks/README.md))

mdarc/DI has an very small but robust code base. It is **production ready** and can be used for small micro-services or large monolithic projects.

##### Features:

[](#features)

- Autowiring: Automatically instantiate and inject dependencies
- Manual configuration: When classes cannot be autowired, you can create them by yourself
- Circular reference detection: It throws a `CircularReferenceException` with enough details to fix the problem

##### What mdarc/DI is not good for:

[](#what-mdarcdi-is-not-good-for)

- Autowiring via setter methods is not supported (and it will never be)
- Autowiring using phpDoc annotations is not supported (and it will never be)
- Automatically injecting dependencies on constructor parameters without type hints is not supported. You must manually configure those cases

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

[](#installation)

### Composer

[](#composer)

Before anything else, use this to add it to your composer.json

```
$ composer require mdarc/di "^1.0.0"
```

Usage
-----

[](#usage)

Creating a container ready to use with autowiring enabled is a matter of creating a `Container` instance:

```
use Mdarc\DI\Container;

$container = new Container();
```

If your classes contain **constructor parameters** that are other objects, then simply:

```
$myClass = $container->get(\Path\To\MyClass::class);
```

As any other DI container, `$myClass` will always get the same instance on the requested class.

If you want to create a new object every time (instead of getting the same object instance) then use the **factory** helper:

```
use Mdarc\DI\Container;
use Mdarc\DI\DI;

$container = new Container([
    \Path\To\MyClass::class => DI::factory(function () {
        return new \Path\To\MyClass();
    }),
]);

$myClass = $container->get(\Path\To\MyClass::class);
```

For those classes that cannot be created using autowiring, then you can add their **definitions**:

```
use Mdarc\DI\Container;

$container = new Container([
    \Monolog\Logger::class => function (Container $c) {
        $config = $c->get(\Path\To\Config::class);
        $logger = new \Monolog\Logger($config->get('name'));
        $logger->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Monolog\Logger::DEBUG));

        return $logger;
    }),
]);

$logger = $container->get(\Monolog\Logger::class);
```

Defining **aliases** for binding interfaces to implementations is simple:

```
use Mdarc\DI\Container;

$container = new Container([
    // Binding Interface to implementation
    \Psr\Log\LoggerInterface::class => \Monolog\Logger::class,
    // Concrete implementation
    \Monolog\Logger::class => function (Container $c) {
        // build Monolog here
    }),
]);

$logger = $container->get(\Psr\Log\LoggerInterface::class);
```

Specifying **arguments** for classes with constructor parameters that are scalar, array or undefined type:

```
use Mdarc\DI\Container;

class MyClass {
    public function __construct(array $config, \Psr\LoggerInterface $logger) { /*...*/ }
}

$definitions = [
    // Binding Interface to implementation
    \Psr\Log\LoggerInterface::class => \Monolog\Logger::class,
    // Concrete implementation
    \Monolog\Logger::class => function (Container $c) {
        // build Monolog here
    },
];

$constructorParameters = [
    MyClass::class => [
        'config' => ['an array', 'of relevant', 'things']
    ],
];
$container = new Container($definitions, $constructorParameters);

$myClass = $container->get(MyClass::class);
```

### License

[](#license)

mdarc/DI is licensed under the MIT License.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity57

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 ~38 days

Total

5

Last Release

2279d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4af464d772ca400ebc9ca086c872d9b9701864da2f926235ba556f82f988e61f?d=identicon)[mdarc](/maintainers/mdarc)

---

Top Contributors

[![mdarc](https://avatars.githubusercontent.com/u/6951918?v=4)](https://github.com/mdarc "mdarc (3 commits)")

---

Tags

dependency-injectioniocioc-containerphpphp7psr-11containerPSR-11Autowiringdependency-injectiondiiocpsr11

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[slince/di

A flexible dependency injection container

20260.4k6](/packages/slince-di)

PHPackages © 2026

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