Optimise Dependency Injection in Laravel
up vote
-1
down vote
favorite
For example
<?php
namespace AppServicesPlace;
use AppContractsPlacePlaceContract;
class PlaceService implements PlaceContract
{
protected $user;
protected $model;
public function __construct($user, $model)
{
$this->user = $user;
$this->model = $model;
}
public function getUserSubmissionResults($place, $type, $request)
{
return (new UserSubmissionResults)->results($place, $type, $request, $this);
}
}
PlaceService is resolved out of the container
Currently UserSubmissionResults is newed up in a method and "$this" is injected
Would it be better to also resolve UserSubmissionResults out of the container with PlaceService as a dependency?
I have a lot of methods using this technique and I'd require a lot of classes being resolved out of the container to achieve the same thing
php laravel
New contributor
add a comment |
up vote
-1
down vote
favorite
For example
<?php
namespace AppServicesPlace;
use AppContractsPlacePlaceContract;
class PlaceService implements PlaceContract
{
protected $user;
protected $model;
public function __construct($user, $model)
{
$this->user = $user;
$this->model = $model;
}
public function getUserSubmissionResults($place, $type, $request)
{
return (new UserSubmissionResults)->results($place, $type, $request, $this);
}
}
PlaceService is resolved out of the container
Currently UserSubmissionResults is newed up in a method and "$this" is injected
Would it be better to also resolve UserSubmissionResults out of the container with PlaceService as a dependency?
I have a lot of methods using this technique and I'd require a lot of classes being resolved out of the container to achieve the same thing
php laravel
New contributor
2
Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
– Toby Speight
2 days ago
Looking at this code, I have no idea what it's supposed to accomplish, dependencies you want to inject, and what kind of flexibility you hope to achieve with dependency injection.
– 200_success
yesterday
I'm newing up a class and injecting "$this" as opposed to resolving UserSubmissionResults out of the container and injecting PlaceService through the constructor
– Lee
yesterday
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
For example
<?php
namespace AppServicesPlace;
use AppContractsPlacePlaceContract;
class PlaceService implements PlaceContract
{
protected $user;
protected $model;
public function __construct($user, $model)
{
$this->user = $user;
$this->model = $model;
}
public function getUserSubmissionResults($place, $type, $request)
{
return (new UserSubmissionResults)->results($place, $type, $request, $this);
}
}
PlaceService is resolved out of the container
Currently UserSubmissionResults is newed up in a method and "$this" is injected
Would it be better to also resolve UserSubmissionResults out of the container with PlaceService as a dependency?
I have a lot of methods using this technique and I'd require a lot of classes being resolved out of the container to achieve the same thing
php laravel
New contributor
For example
<?php
namespace AppServicesPlace;
use AppContractsPlacePlaceContract;
class PlaceService implements PlaceContract
{
protected $user;
protected $model;
public function __construct($user, $model)
{
$this->user = $user;
$this->model = $model;
}
public function getUserSubmissionResults($place, $type, $request)
{
return (new UserSubmissionResults)->results($place, $type, $request, $this);
}
}
PlaceService is resolved out of the container
Currently UserSubmissionResults is newed up in a method and "$this" is injected
Would it be better to also resolve UserSubmissionResults out of the container with PlaceService as a dependency?
I have a lot of methods using this technique and I'd require a lot of classes being resolved out of the container to achieve the same thing
php laravel
php laravel
New contributor
New contributor
edited yesterday
New contributor
asked 2 days ago
Lee
11
11
New contributor
New contributor
2
Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
– Toby Speight
2 days ago
Looking at this code, I have no idea what it's supposed to accomplish, dependencies you want to inject, and what kind of flexibility you hope to achieve with dependency injection.
– 200_success
yesterday
I'm newing up a class and injecting "$this" as opposed to resolving UserSubmissionResults out of the container and injecting PlaceService through the constructor
– Lee
yesterday
add a comment |
2
Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
– Toby Speight
2 days ago
Looking at this code, I have no idea what it's supposed to accomplish, dependencies you want to inject, and what kind of flexibility you hope to achieve with dependency injection.
– 200_success
yesterday
I'm newing up a class and injecting "$this" as opposed to resolving UserSubmissionResults out of the container and injecting PlaceService through the constructor
– Lee
yesterday
2
2
Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
– Toby Speight
2 days ago
Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
– Toby Speight
2 days ago
Looking at this code, I have no idea what it's supposed to accomplish, dependencies you want to inject, and what kind of flexibility you hope to achieve with dependency injection.
– 200_success
yesterday
Looking at this code, I have no idea what it's supposed to accomplish, dependencies you want to inject, and what kind of flexibility you hope to achieve with dependency injection.
– 200_success
yesterday
I'm newing up a class and injecting "$this" as opposed to resolving UserSubmissionResults out of the container and injecting PlaceService through the constructor
– Lee
yesterday
I'm newing up a class and injecting "$this" as opposed to resolving UserSubmissionResults out of the container and injecting PlaceService through the constructor
– Lee
yesterday
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Lee is a new contributor. Be nice, and check out our Code of Conduct.
Lee is a new contributor. Be nice, and check out our Code of Conduct.
Lee is a new contributor. Be nice, and check out our Code of Conduct.
Lee is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207679%2foptimise-dependency-injection-in-laravel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
– Toby Speight
2 days ago
Looking at this code, I have no idea what it's supposed to accomplish, dependencies you want to inject, and what kind of flexibility you hope to achieve with dependency injection.
– 200_success
yesterday
I'm newing up a class and injecting "$this" as opposed to resolving UserSubmissionResults out of the container and injecting PlaceService through the constructor
– Lee
yesterday