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










share|improve this question









New contributor




Lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 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















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










share|improve this question









New contributor




Lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 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













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










share|improve this question









New contributor




Lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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






share|improve this question









New contributor




Lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday





















New contributor




Lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Lee

11




11




New contributor




Lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 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




    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















active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");

StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Lee is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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






























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.










 

draft saved


draft discarded


















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.















 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Quarter-circle Tiles

build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

Mont Emei