From 9f7d515f75c1ec1c7634206450224215f4feb956 Mon Sep 17 00:00:00 2001 From: Skeptic Spriggan Date: Sat, 27 Jan 2024 17:12:37 +0100 Subject: [PATCH] Explain why DI fails sometimes and how to fix this (#20010) --- docs/guide/concept-di-container.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/guide/concept-di-container.md b/docs/guide/concept-di-container.md index 4a87a9c3d44..fb312e553c4 100644 --- a/docs/guide/concept-di-container.md +++ b/docs/guide/concept-di-container.md @@ -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 ---------------