mercredi 18 novembre 2020

Why using Laravel Service Container instead of creating an instance directly?

I have a question, why I need to use Laravel Service Container like this:

$this->app->bind('HelpSpot\API', function ($app) {
    return new \HelpSpot\API($app->make('HttpClient'));
});

and call it in the controller like this: resolve('\HelpSpot\API')->domeSomething()

While we can create an instance directly like this:

(new \HelpSpot\API)->domeSomething()

Thank you!

Aucun commentaire:

Enregistrer un commentaire