Dependency injection


I would like to set an attribute of an arbitrary class for all instances through configuration.

I understand how to do it for components, or modules (through the app config array), but I don’t know how to do it for an arbitrary class.

Let’s say I have

use yii\base\Model;

class Myclass extends Model {

  public $var = 5;



I would like to change, from the config file for example, the default value of $var to 10 for all instances (without changing the source code of the class ;-).

Isn’t it possible to do this with DI? How?

(PS: Myclass is neither a component, nor a module, just an ordinary Yii2 model.)

Thank you.