From 811753df211ed2af9a1218f54f36cadf5f46e3ed Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 16 Jan 2026 13:47:23 +0300 Subject: [PATCH 1/4] Expanded closure example in DI --- src/guide/concept/di-container.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/guide/concept/di-container.md b/src/guide/concept/di-container.md index b12f4a45..a6e70af5 100644 --- a/src/guide/concept/di-container.md +++ b/src/guide/concept/di-container.md @@ -257,7 +257,13 @@ MyServiceInterface::class => static function(ContainerInterface $container) { }, ``` -As an argument, a container is passed to a closure. It can be used to resolve dependencies. +Additionally, to `ContainerInterface` you can get any service by requesting it as an argument: + +```php +MyServiceInterface::class => static function(ConnectionInterface $db) { + return new MyService($db); +}, +``` It's possible to use a static method call: From 93e26139f3724dc6f2edbe85791b4fe44e4e8b0a Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 16 Jan 2026 13:50:19 +0300 Subject: [PATCH 2/4] Update src/guide/concept/di-container.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/guide/concept/di-container.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/guide/concept/di-container.md b/src/guide/concept/di-container.md index a6e70af5..cf7683a2 100644 --- a/src/guide/concept/di-container.md +++ b/src/guide/concept/di-container.md @@ -257,7 +257,7 @@ MyServiceInterface::class => static function(ContainerInterface $container) { }, ``` -Additionally, to `ContainerInterface` you can get any service by requesting it as an argument: +In addition to `ContainerInterface`, you can get any service by requesting it as an argument: ```php MyServiceInterface::class => static function(ConnectionInterface $db) { From a396d153a7cdd0d4e0093f27f29753bdd17951f1 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 16 Jan 2026 13:53:06 +0300 Subject: [PATCH 3/4] Review fix --- src/guide/concept/di-container.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/guide/concept/di-container.md b/src/guide/concept/di-container.md index cf7683a2..e620365e 100644 --- a/src/guide/concept/di-container.md +++ b/src/guide/concept/di-container.md @@ -257,7 +257,8 @@ MyServiceInterface::class => static function(ContainerInterface $container) { }, ``` -In addition to `ContainerInterface`, you can get any service by requesting it as an argument: +Additionally, to `ContainerInterface`, you can request any registered service directly as a closure parameter. +The injector will automatically resolve and inject these: ```php MyServiceInterface::class => static function(ConnectionInterface $db) { From 0be2394b2d35ef482f7ac778fe886cb950eaae36 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 16 Jan 2026 14:09:08 +0300 Subject: [PATCH 4/4] Remove duplicate --- src/guide/concept/di-container.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/guide/concept/di-container.md b/src/guide/concept/di-container.md index e620365e..04fd695b 100644 --- a/src/guide/concept/di-container.md +++ b/src/guide/concept/di-container.md @@ -118,9 +118,6 @@ That's what dependency containers are for. A dependency injection (DI) container is an object that knows how to instantiate and configure objects and all objects they depend on. -> [!NOTE] -> The container contains only shared instances. If you need a factory, use the dedicated [yiisoft/factory](https://github.com/yiisoft/factory) package. - Yii provides the DI container feature through the [yiisoft/di](https://github.com/yiisoft/di) package and [yiisoft/injector](https://github.com/yiisoft/injector) package.