mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-16 14:29:30 +08:00
docs/guide/concept-di-container.md revised [ci skip]
This commit is contained in:
@@ -15,6 +15,7 @@ dependency injection:
|
|||||||
* Constructor injection;
|
* Constructor injection;
|
||||||
* Setter and property injection;
|
* Setter and property injection;
|
||||||
* PHP callable injection.
|
* PHP callable injection.
|
||||||
|
* Method signiture injection.
|
||||||
|
|
||||||
|
|
||||||
### Constructor Injection <span id="constructor-injection"></span>
|
### Constructor Injection <span id="constructor-injection"></span>
|
||||||
@@ -116,10 +117,12 @@ $foo = $container->get('Foo');
|
|||||||
By doing so, the person who wants to configure the `Foo` class no longer needs to be aware of how it is built.
|
By doing so, the person who wants to configure the `Foo` class no longer needs to be aware of how it is built.
|
||||||
|
|
||||||
|
|
||||||
### Controller action injection
|
### Method signature injection <span id="method-signature-injection"></span>
|
||||||
|
|
||||||
Controller action injection is a special type of DI where dependecies are resolved per action which is useful for
|
Method signature injection is a special type of DI where dependecies are declared using the type hints of
|
||||||
keeping dependencies number low in MVC controllers.
|
method signatures and resolved in the runtime when the method is acturally called. It is particularly useful for keeping
|
||||||
|
the MVC controllers slim and light-weighted since it doesn't require you to configure all the possible dependencies
|
||||||
|
of the controller beforehand.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
public function actionSend($email, EmailValidator $validator)
|
public function actionSend($email, EmailValidator $validator)
|
||||||
|
|||||||
Reference in New Issue
Block a user