PHPackages                             koriym/dii - 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. [Framework](/categories/framework)
4. /
5. koriym/dii

ActiveLibrary[Framework](/categories/framework)

koriym/dii
==========

Dependency Injection Plugin for Yii 1

0.5.0(1y ago)17195.8k↓27.4%3[1 PRs](https://github.com/koriym/dii/pulls)MITPHPPHP ^7.1 || ^8.0

Since Oct 25Pushed 3mo ago6 watchersCompare

[ Source](https://github.com/koriym/dii)[ Packagist](https://packagist.org/packages/koriym/dii)[ RSS](/packages/koriym-dii/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (7)Versions (15)Used By (0)

Dii
===

[](#dii)

Dependency Injection Container Plugin for Yii 1
-----------------------------------------------

[](#dependency-injection-container-plugin-for-yii-1)

This plugin adds the ability to configure object instances and their dependencies before they are used, and to store them into a container class to easy access.

It uses the clean and flexible [Ray.Di](https://github.com/ray-di/Ray.Di) DI framework which is a PHP dependency injection framework in the style of "Google Guice".

Ray.Di also allows you to program using AOP, that is, decorating the configured instances so some logic can be run before or after any of their methods.

Configuration
-------------

[](#configuration)

### Bootstrap file

[](#bootstrap-file)

Use composer autoloader instead of Yii autoloader.

```
// composer autoloader
require dirname(__DIR__) . '/vendor/autoload.php';
spl_autoload_unregister([YiiBase::class, 'autoload']);

// set context module
Dii::setContext(\YourVendor\YourProject\Context\App::class);

// run the application
Yii::createWebApplication()->run();
```

### Binding module

[](#binding-module)

Modules are classes that describe how instances and their dependencies should be constructed, they provide a natural way of grouping configurations. An example module looks like this:

```
