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

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

iidestiny/dependency-injection
==============================

Enable your methods to use dependency injection

1.1(3y ago)281902MITPHPPHP &gt;=7.0CI failing

Since Feb 26Pushed 3y ago1 watchersCompare

[ Source](https://github.com/iiDestiny/dependency-injection)[ Packagist](https://packagist.org/packages/iidestiny/dependency-injection)[ RSS](/packages/iidestiny-dependency-injection/feed)WikiDiscussions master Synced today

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

 dependency-injection
======================

[](#-dependency-injection-)

[![](https://camo.githubusercontent.com/a4c8be956a8cdd037660613e1fe8629087b8e86aaf68fb184370764a3738ac91/68747470733a2f2f7472617669732d63692e6f72672f696944657374696e792f646570656e64656e63792d696e6a656374696f6e2e7376673f6272616e63683d6d6173746572)](https://github.com/iiDestiny/dependency-injection)[![](https://camo.githubusercontent.com/78882ad5fef476122daedfb040304ec0b2543b80893a6dbf7155e38d450404e0/68747470733a2f2f706f7365722e707567782e6f72672f696964657374696e792f646570656e64656e63792d696e6a656374696f6e2f762f737461626c65)](https://github.com/iiDestiny/dependency-injection)[![](https://camo.githubusercontent.com/d437814559e5c3503056e160b5acfae87a6bbf98ba3349083b7367840c0164ae/68747470733a2f2f706f7365722e707567782e6f72672f696964657374696e792f646570656e64656e63792d696e6a656374696f6e2f646f776e6c6f616473)](https://github.com/iiDestiny/dependency-injection)[![](https://camo.githubusercontent.com/9235990a218d9755af83227b47a91b988063d780fec719d1e349e40f0636b3e5/68747470733a2f2f706f7365722e707567782e6f72672f696964657374696e792f646570656e64656e63792d696e6a656374696f6e2f762f756e737461626c65)](https://github.com/iiDestiny/dependency-injection)[![](https://camo.githubusercontent.com/a8a6219cf0313b681948382bcbcc27a34ae00572d463437bd92ebb1df58647c9/68747470733a2f2f6261646765732e66726170736f66742e636f6d2f6f732f76312f6f70656e2d736f757263652e7376673f763d313033)](https://github.com/iiDestiny/dependency-injection)[![](https://camo.githubusercontent.com/75e0aa1a419a8c5ccd3c23e30e18e5337c3a62f567093c64da35495f8cdc9f57/68747470733a2f2f706f7365722e707567782e6f72672f696964657374696e792f646570656e64656e63792d696e6a656374696f6e2f6c6963656e7365)](https://github.com/iiDestiny/dependency-injection)

 Let your custom class methods also enjoy dependency injection.

感谢关注「GitHub 热门」公众号，带你了解技术圈内热门新鲜事！
[![](https://camo.githubusercontent.com/402b68eecf0ecdce4dbd6f633a2a4fbd1a7cffb2f636fdb97e80e1191eee724a/68747470733a2f2f63646e2e6c6561726e6b752e636f6d2f75706c6f6164732f696d616765732f3230323031312f30392f343433302f717345437739437467762e6a7067216c61726765)](https://camo.githubusercontent.com/402b68eecf0ecdce4dbd6f633a2a4fbd1a7cffb2f636fdb97e80e1191eee724a/68747470733a2f2f63646e2e6c6561726e6b752e636f6d2f75706c6f6164732f696d616765732f3230323031312f30392f343433302f717345437739437467762e6a7067216c61726765)

Doc
---

[](#doc)

- [中文文档](https://github.com/iiDestiny/dependency-injection/blob/master/Zh-README.md)

Requirement
-----------

[](#requirement)

- PHP &gt;= 7.0

install
-------

[](#install)

```
composer require iidestiny/dependency-injection -vvv
```

Usage
-----

[](#usage)

Use helper methods

```
    // register class
    di_register(Tools::class)

    // Call a method in a class
    di_register(Tools::class)->generate($param, $param, $param)

    // more
    di_register(Tools::class)->foo($bar)
```

example
-------

[](#example)

Sometimes we need dependency injection when calling our own defined methods. See the example below.

```
