PHPackages                             kodcube/dependency-injection - 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. kodcube/dependency-injection

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

kodcube/dependency-injection
============================

Dependency Injection Container

0.1.2(9y ago)148PHPPHP &gt;=7.0.0

Since Jul 17Pushed 9y ago1 watchersCompare

[ Source](https://github.com/kodcube/dependency-injection)[ Packagist](https://packagist.org/packages/kodcube/dependency-injection)[ RSS](/packages/kodcube-dependency-injection/feed)WikiDiscussions master Synced 2mo ago

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

Dependency Injection Container / Service Locator / Object Builder
=================================================================

[](#dependency-injection-container--service-locator--object-builder)

This package is Recursive Dependency Injection Container (DiC) / Service Locator / Object Builder

It has been designed to take it's dependency configuration map as part of it's construction, so rather than setting up all the dependencies at runtime they can be loaded from a configuration file or files.

So as long as you can create an array, the configuration is injected at construction.

### Main Features

[](#main-features)

- Build a Service/Object/Class based on a class name or alias
- Build a Class/Object that requires other dependencies
- Cache built Service/Object/Class for reuse in other classes (e.g. Database Connections)
- Build a Object/Class with a combination of passed and required dependencies
- Recursive Object Creation

### Limitations

[](#limitations)

- Does not inject dependencies for methods other than \_\_constructor
- Does not inject dependencies for setters

### Requirements

[](#requirements)

- PHP 7
- container-interop/container-interop
- [Usage](#usage) - *Basic usage examples*

    - [Create Container](#create-container)
    - [Get Object from Container](#get-object-from-container)
    - [Check if Alias\\Class Exists in Container](#check-if-aliasclass-exists-in-container)
    - [Make Object](#make-object)
- [Methods](https://github.com/kodcube/dependency-injection/wiki/Container#methods)
- [Aliases](https://github.com/kodcube/dependency-injection/wiki/Aliases-&-Service-Locators)
- [AutoWiring](https://github.com/kodcube/dependency-injection/wiki/Autowiring)

[Configuration Examples](https://github.com/kodcube/dependency-injection/wiki/Configuration)

Usage
-----

[](#usage)

### Create Container

[](#create-container)

```
$di = new KodCube\DependencyInjection\Container();

or

$di = new KodCube\DependencyInjection\Container($config);

or

$di = new KodCube\DependencyInjection\Container([
  'MyAlias' => 'Vendor\Package\Class',
  'Vendor\Package\Interface' => 'Vendor\Package\Class'
])
```

### Get Object from Container using an alias

[](#get-object-from-container-using-an-alias)

Using Alias

```
$object = $di->get('MyAlias');

or

$object = $di('MyAlias');

or

$object = $di->MyAlias();
```

Using Class Name

```
$object = $di->get('Vendor\Package\Class');

or

$object = $di('Vendor\Package\Class');
```

Using Interface Name (requires dependency map)

```
$object = $di->get('Vendor\Package\Interface');

or

$object = $di('Vendor\Package\Interface');
```

### Check if Alias\\Class Exists in Container

[](#check-if-aliasclass-exists-in-container)

```
Alias
$object = $di->has('MyAlias');

Class
$object = $di->has('Vendor\Package\Class');
```

### Make Object

[](#make-object)

Make a object using the DiC using passed arguments.

This will also take advantage of the autowiring properties of the container.

Note: Objects created with additional arguments are not cached by the container.

```
$object = $di->make('Vendor\Package\Class','argument1','argument2');
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

Total

3

Last Release

3587d ago

### Community

Maintainers

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

---

Top Contributors

[![srmiles](https://avatars.githubusercontent.com/u/1708004?v=4)](https://github.com/srmiles "srmiles (13 commits)")

---

Tags

container-interopdependency-injectionphp7containerdependency-injectiondi

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kodcube-dependency-injection/health.svg)

```
[![Health](https://phpackages.com/badges/kodcube-dependency-injection/health.svg)](https://phpackages.com/packages/kodcube-dependency-injection)
```

###  Alternatives

[php-di/php-di

The dependency injection container for humans

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

A serializable dependency injection container with constructor and setter injection, interface and trait awareness, configuration inheritance, and much more.

356968.3k58](/packages/aura-di)[mrclay/props-dic

Props is a simple DI container that allows retrieving values via custom property and method names

3611.7M3](/packages/mrclay-props-dic)[slince/di

A flexible dependency injection container

20260.4k6](/packages/slince-di)[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)
