1

What is the difference between instancing a DI in the constructor like:

private $routingService;

public function __construct(RoutingService $routingService)
{
    $this->routingService = $routingService;
}

and doing it with facade App::make('RoutingService')

EDIT:

I'm not asking for what is better, but rather what are their practical/functional differences except the obvious one that constructor one is available on the class level, and facade one is available only in method called.

3
  • Possible duplicate of In Laravel, any downside to using App::make('') rather than constructor injection? Commented Oct 31, 2017 at 13:30
  • DI in the constructor can only work if you make your class using the app container so it's not two alternatives it's just a matter of when you use the container Commented Oct 31, 2017 at 13:31
  • Does App::make() still count as "coupling" one class to another? Commented Nov 7, 2017 at 9:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.