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

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

stratadox/di
============

A most simplistic Dependency Injection Container

v1.0.2(8y ago)1136MITPHPPHP &gt;=7.0

Since Jul 1Pushed 7y ago2 watchersCompare

[ Source](https://github.com/Stratadox/Di)[ Packagist](https://packagist.org/packages/stratadox/di)[ RSS](/packages/stratadox-di/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (3)Versions (4)Used By (0)

Di
==

[](#di)

[![Build Status](https://camo.githubusercontent.com/840463801ba2a7ab2dbfe5739d2bfdac416d7312976f4609cea5eea7aba0fd1a/68747470733a2f2f7472617669732d63692e6f72672f537472617461646f782f44692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Stratadox/Di)[![Coverage Status](https://camo.githubusercontent.com/552703fc8d0413aa5ce8be60b382747c5a744c0462f905c2d4a84c90a30a9baf/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f537472617461646f782f44692f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Stratadox/Di?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/7467e0e498eb9da05346ac9332612bbc581ddf89e4f5cca3a2cd85fde650b6db/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f537472617461646f782f44692f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Stratadox/Di/?branch=master)

A minimalistic Dependency Injection Container

Services are lazy loaded through the use of anonymous functions.

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

[](#installation)

Install using composer:

```
composer require stratadox/di

```

Basic usage
-----------

[](#basic-usage)

```
// Create container
$container = new DependencyContainer();

// Set service
$container->set('some_service', function () {
    return new SomeService();
});

// Get service
$service = $container->get('some_service');

// Check if service exists
$hasService = $container->has('some_service');

// Remove service
$container->forget('some_service');
```

Alternatively, you can use the array syntax:

```
// Create container
$container = new ArrayAdapter(new DependencyContainer());

// Set service
$container['some_service'] = function () {
    return new SomeService();
};

// Get service
$service = $container['some_service'];

// Check if service exists
$hasService = isset($container['some_service']);

// Remove service
unset($container['some_service']);
```

By decorating the container with an AutoWiring object, a large portion of the configuration effort can be automated:

```
// Create container
$container = AutoWiring::the(new DependencyContainer);

$foo = $container->get(Foo::class);
```

Dependent services
------------------

[](#dependent-services)

You can construct services that use other services by passing the DI container in your anonymous function.

```
$container = new DependencyContainer();

$container->set('collaborator', function () {
    return new Collaborator();
});

$container->set('main_service', function () use ($container) {
    return new MainService($container->get('collaborator'));
});

$service = $container->get('main_service');
```

Because services are lazy it does not matter in which order you define them, as long they are all defined when you request one. So in the example above we could define `main_service` before `collaborator`, so long as we don't request `main_service` before `collaborator` is defined.

Parameters
----------

[](#parameters)

To pass other parameters to your services, pass them to your anonymous function as well.

```
$dsn = 'mysql:host=localhost;dbname=testdb';
$username = 'admin';
$password = 'secret';

$container = new DependencyContainer();
$container->set('database', function () use ($dsn, $username, $password) {
    return new DatabaseConnection($dsn, $username, $password);
});
```

Cache
-----

[](#cache)

By default, services are cached. You can trigger the factory on each request by setting cache to false.

```
// Set service
$container->set('some_service', function () {
    return new SomeService();
}, false);
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 94.2% 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 ~103 days

Total

3

Last Release

3034d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5333260?v=4)[Stratadox](/maintainers/Stratadox)[@Stratadox](https://github.com/Stratadox)

---

Top Contributors

[![Stratadox](https://avatars.githubusercontent.com/u/5333260?v=4)](https://github.com/Stratadox "Stratadox (163 commits)")[![rpkamp](https://avatars.githubusercontent.com/u/1059790?v=4)](https://github.com/rpkamp "rpkamp (10 commits)")

---

Tags

containerdependencyinjectiondidicSimplelightweightsmallinversionstratadox

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[league/container

A fast and intuitive dependency injection container.

86387.8M343](/packages/league-container)[miladrahimi/phpcontainer

Dependency injection (IoC) container for PHP projects

1322.7k2](/packages/miladrahimi-phpcontainer)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2857.5k2](/packages/capsule-di)

PHPackages © 2026

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