{
    "href": "/post/2017/10/17/choose-dependency-injection-if-you-can/",
    "relId": "2017/10/17/choose-dependency-injection-if-you-can",
    "title": "Choose Dependency Injection \u2014 If You Can",
    "author": "pmjones",
    "markup": "html",
    "tags": [
        {
            "href": "/tag/php/",
            "relId": "php",
            "title": "PHP",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        },
        {
            "href": "/tag/programming/",
            "relId": "programming",
            "title": "Programming",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        }
    ],
    "created": "2017-10-17 14:00:18 UTC",
    "updated": [
        "2017-10-17 14:00:18 UTC"
    ],
    "html": "<p>Some people say, \"You don't need to use dependency injection for everything. Sometimes dependency injection is not the best choice.\"</p>\n<p>It occurs to me that the people who say this are the ones who <em>can't</em> use it for everything. They say \"choose what's best for your situation\", but their situation precludes the use of dependency injection in the first place.</p>\n<p>Anyone who says \"X is not always the best choice\", but does not have X as an available option, is being disingenuous. They are not choosing against X based on an examination of the tradeoffs involved. Instead, they are making a virtue out of necessity, then posing as virtuous for not having better choices available.</p>\n<p>Dependency injection is, by default and until proven otherwise, the best choice -- when you have that choice available to you.</p>\n<p>If that choice is <em>not</em> available to you, if you <em>cannot</em> construct an object using any form of dependency injection (constructor injection, setter injection, etc.), then you need to consider if the code in question has been designed poorly.</p>\n"
}
