PHPackages                             phpnomad/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. phpnomad/di

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

phpnomad/di
===========

2.0.1(3w ago)05.7k↓30%[1 issues](https://github.com/phpnomad/di/issues)[1 PRs](https://github.com/phpnomad/di/pulls)14MITPHPCI passing

Since Oct 11Pushed 3w ago2 watchersCompare

[ Source](https://github.com/phpnomad/di)[ Packagist](https://packagist.org/packages/phpnomad/di)[ Docs](https://github.com/phpnomad/core)[ RSS](/packages/phpnomad-di/feed)WikiDiscussions main Synced yesterday

READMEChangelog (3)Dependencies (4)Versions (11)Used By (14)

phpnomad/di
===========

[](#phpnomaddi)

[![Latest Version](https://camo.githubusercontent.com/df9d32b256e0f4765e285f673feac5f083215deb8f196ac8a7ec92e93fd400a0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068706e6f6d61642f64692e737667)](https://packagist.org/packages/phpnomad/di) [![Total Downloads](https://camo.githubusercontent.com/d31d8d9d859a98feccb4a591f9482ca22de3d02c9990a3e4de2bb0959925596e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068706e6f6d61642f64692e737667)](https://packagist.org/packages/phpnomad/di) [![PHP Version](https://camo.githubusercontent.com/7c8325cd20208f1142a679ee27b381fb55ee371c89d5acf43e11a0b14767f619/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7068706e6f6d61642f64692e737667)](https://packagist.org/packages/phpnomad/di) [![License](https://camo.githubusercontent.com/4cd75aa25b02c35f3c5a66b40651c2d6532f622ce80a74e61f1aaa4e1414ba02/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068706e6f6d61642f64692e737667)](https://packagist.org/packages/phpnomad/di)

`phpnomad/di` is the contract-only dependency injection package for [PHPNomad](https://phpnomad.com). It defines the interfaces a container has to satisfy (`InstanceProvider`, `HasBindings`, `CanSetContainer`), a `HasSettableContainer` trait for classes that need the container handed to them after construction, and a `DiException` type. That's the entire package. It has zero runtime dependencies.

The concrete container implementation lives in a separate package, [`phpnomad/di-container`](https://packagist.org/packages/phpnomad/di-container). This split exists so your code can depend on the contracts without forcing a specific container implementation on anyone downstream. You can swap the container for a different implementation without touching any of the classes that inject `InstanceProvider`. `phpnomad/di-container` is the standard implementation that ships with PHPNomad and has been running in production for years across [Siren](https://sirenaffiliates.com) and several other client systems.

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

[](#installation)

```
composer require phpnomad/di
```

Most applications also install `phpnomad/di-container`, which provides the concrete `Container` class that implements these interfaces:

```
composer require phpnomad/di-container
```

Quick Start
-----------

[](#quick-start)

Classes declare `InstanceProvider` as a constructor parameter and use it to resolve dependencies by class name at runtime. Here's a report builder that needs a datastore it doesn't hold as a direct property:

```
