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

ActiveLibrary

free-elephants/di
=================

IoC, constructor dependency injection

4.1.2(2mo ago)418.2k↓19.2%12BSD-2-ClausePHPPHP ^7.4|^8.0CI passing

Since Dec 1Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/FreeElephants/php-di)[ Packagist](https://packagist.org/packages/free-elephants/di)[ RSS](/packages/free-elephants-di/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (30)Used By (2)

Simple PHP Constructor-based Dependency Injection
=================================================

[](#simple-php-constructor-based-dependency-injection)

[![Build Status](https://github.com/FreeElephants/php-di/workflows/CI/badge.svg)](https://github.com/FreeElephants/php-di/actions)[![codecov](https://camo.githubusercontent.com/e85b19e18966cf7e4b771d288e4bc7cf5e0a9df5cdec2b7a6b1ebaef0c691499/68747470733a2f2f636f6465636f762e696f2f67682f46726565456c657068616e74732f7068702d64692f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/FreeElephants/php-di)[![Installs](https://camo.githubusercontent.com/e584d55f6b2d970187a86147e1bfc4ef20480eaf8314bbd07fcffbbc4a5fc215/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f667265652d656c657068616e74732f64692e737667)](https://packagist.org/packages/free-elephants/di)[![Releases](https://camo.githubusercontent.com/3cffc0b614984349364953c88d9521b5fb9c1f9ff356f0f63e8c9616492fa2f6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f667265652d656c657068616e74732f64692e737667)](https://github.com/FreeElephants/php-di/releases)

*Configure less. Do more.*

Framework-agnostic Dependency Injection tool and PSR-11 implementation provider.

Requirements
------------

[](#requirements)

PHP 7.4|8+

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

[](#installation)

```
composer require free-elephants/di
```

Usage
-----

[](#usage)

Your entry php script (index.php or some background-job runner)

```
$components = require 'components.php';
$di = (new \FreeElephants\DI\InjectorBuilder)->buildFromArray($components);
$app = $di->createInstance(\YourApplication::class);
$app->run();
```

Your `components.php` file with dependencies description should look like this:

```
