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

ActiveLibrary

ericsnguyen/simple-di
=====================

a simple dependency injection library

v1.0.4(5y ago)0163MITPHPPHP ^7.4

Since Oct 17Pushed 4y agoCompare

[ Source](https://github.com/thicongtu2/SimpleDi)[ Packagist](https://packagist.org/packages/ericsnguyen/simple-di)[ RSS](/packages/ericsnguyen-simple-di/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (6)Used By (0)

Simple DI
=========

[](#simple-di)

An easily setup dependency injection library that help you can set up Dependency injection in your project faster.

Documentation
-------------

[](#documentation)

### Step I.

[](#step-i)

**Mark with your class** as `@Export()` to Simple DI release this class need to be keep on container. In any other class. if you want to inject by property, **mark this property as** `@Import()`

```
use SimpleDi\Annotations\Export;
use SimpleDi\Annotations\Import;

/**
* @Export()
 */
class TrainingPlanController extends AbstractController
{
    /**
     * @Import()
     * @var MessageFactory
     */
    protected MessageFactory $mf;
    /**
     * @Import()
     * @var CourseService
     */
    protected CourseService $courseService;
}
```

We have an hacked for class that ended with **Controller**. It doesn't need mark as `@Export` at all.

### Step II

[](#step-ii)

I have a small script that find any class that mark with `@Export` and create your own `$register` array. so you don't need to create by hand anymore. Stand at your project root. then run this command:

- PROJECT = root project folder
- FILE = the file that store registry map

```
PROJECT=application FILE=proxy/registry.php ./vendor/ericsnguyen/simple-di/bin/generate
```

it would print some error, but ignore it, after run, double check it.

### Step III

[](#step-iii)

At your `index.php` or any start endpoint file. put the configuration for `SimpleDi`

```
// you can put your `array` that act as your old DI container to it as param
$container = new class implements \SimpleDi\Container\IContainer(){
    // in my library we have SdContainer class that implements IContainer
    // but you can implement one if you want.
};

$register = [
    YourInterface::class=> YourImplementClass:class
];

SimpleDi::build([
       // I have a variable $GLOBALS act as an instances holder for my container
      'container'=>new SdContainer($GLOBALS),
      // an $register array.
      'registry'=> include PROJECT_ROOT."/proxy/registry.php",
       // it is optional -> get any singleton existed in your project, but you can ignore it.
      'root_class'=> Singleton::class
]);
```

and at anywhere you want to get this instance:

```
 // at my routes table reader.
$controller = App::resolver($controllerName);
```

###  Health Score

26

—

LowBetter than 46% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community6

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

Total

5

Last Release

1981d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2dcf63ef46261a94307b7e2b87fb2d2973ee4bc7f6e5705dd0f7fd5f5ddf9b9d?d=identicon)[ericsnguyen](/maintainers/ericsnguyen)

---

Top Contributors

[![anhngocnguyen94](https://avatars.githubusercontent.com/u/67720617?v=4)](https://github.com/anhngocnguyen94 "anhngocnguyen94 (17 commits)")

---

Tags

containerdependency-injectionphpdependency-injectiondisimple di

### Embed Badge

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

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k47.0M874](/packages/php-di-php-di)[laminas/laminas-servicemanager

Factory-Driven Dependency Injection Container

15954.0M648](/packages/laminas-laminas-servicemanager)[level-2/dice

A minimalist Dependency injection container (DIC) for PHP. Please note: 3.0+ is only compatible with PHP 7.0. The 2.0 branch is compatbile with PHP 5.6.

438712.4k16](/packages/level-2-dice)[aura/di

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

357963.4k50](/packages/aura-di)[yiisoft/injector

PSR-11 compatible injector. Executes a callable and makes an instances by injecting dependencies from a given DI container.

942.5M32](/packages/yiisoft-injector)[mrclay/props-dic

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

3611.3M2](/packages/mrclay-props-dic)

PHPackages © 2026

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