Skip to content

Commit

Permalink
Explain why DI fails sometimes and how to fix this (#20010)
Browse files Browse the repository at this point in the history
  • Loading branch information
skepticspriggan committed Jan 27, 2024
1 parent 0027227 commit 9f7d515
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/guide/concept-di-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,18 @@ class HotelController extends Controller
}
```

Note that not all core code supports DI due to performance concerns. You can add support if needed by overriding
the method responsible for instantiating the class and making sure it uses [[Yii::createObject()]].

For example, you can add DI support to [[yii\db\ActiveRecord]] models by overriding the `instantiate()` method:

```php
public static function instantiate($row)
{
return Yii::createObject(static::class);
}
```

Advanced Practical Usage <span id="advanced-practical-usage"></span>
---------------

Expand Down

0 comments on commit 9f7d515

Please sign in to comment.