Yeah I thought so.
There are dependencies that I only require in certain events. When they are passed there I don’t need to inject them into the constructor of my classes. Otherwise I need to call the invoke method in the event handler and build a wrapper just in order to pass a service or something like that.
I’m still trying to reduce the usage of the service locator. Usually I would just grab the required services via
Yii::$app so I’m searching for good methods to replace it without having too many parameters in my constructor.
How would you do that?
Let’s say after a record is saved I want to send a mail to certain users. (I know how to write the code for that, it’s just about resolving the dependencies for the
yii/web/View, a mailer component and maybe 1/2 others without calling
Yii::$app and without having all of those in the constructor of the class where
Event::on is called.
Of course I could create a single class for each event but that seems a little bit over the top to have about 50+ classes for each event