3 months ago

Can I define dependency injection in any class?

Posted 3 months ago by xwy

Hello, I am using Laravel 5.1. I know I can inject any dependency I need in controller, middleware, console class constructor. But what if I use my own class, for example I have an ExperienceService class and an ExperienceUtil class. I want to inject ExperienceUtil into ExperienceService, So can I do like this:

class ExperienceService{
    private $util;

    public function __construct(ExperienceUtil $util){
        $this->util = $util;

Please sign in or create an account to participate in this conversation.