Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/guide/concept/di-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -257,7 +254,14 @@ 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 request any registered service directly as a closure parameter.
The injector will automatically resolve and inject these:

```php
MyServiceInterface::class => static function(ConnectionInterface $db) {
return new MyService($db);
},
```

It's possible to use a static method call:

Expand Down