{
    "href": "/post/2021/09/13/capsule-3-clean-concise-composable-dependency-injection/",
    "relId": "2021/09/13/capsule-3-clean-concise-composable-dependency-injection",
    "title": "Capsule 3: Clean, Concise, Composable Dependency Injection",
    "author": "pmjones",
    "tags": [
        {
            "href": "/tag/programming/",
            "relId": "programming",
            "title": "Programming",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        },
        {
            "href": "/tag/php/",
            "relId": "php",
            "title": "PHP",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        },
        {
            "href": "/tag/capsule/",
            "relId": "capsule",
            "title": "Capsule",
            "author": null,
            "created": "2021-09-13 21:01:20 UTC",
            "updated": [
                "2021-09-13 21:01:20 UTC"
            ],
            "markup": "markdown"
        }
    ],
    "created": "2021-09-13 21:01:20 UTC",
    "updated": [
        "2021-09-13 21:01:20 UTC",
        "2021-09-13 21:51:32 UTC",
        "2021-09-13 21:52:00 UTC",
        "2021-09-14 03:59:31 UTC"
    ],
    "markup": "markdown",
    "html": "<p>I'm happy to announce that I have released <a href=\"http://capsulephp.com\">Capsule</a> 3.2.0, an autowiring dependency injection system for PHP 8. (Earlier 3.x releases started a couple of weeks ago, but this is the first proper announcement.)</p>\n<p>Capsule works a little bit differently from other autowiring DI systems. The biggest difference is that configuration entries are stored as dynamic public properties on a <em>Definitions</em> object. That makes it very easy to obtain and modify not only object definitions, but also primitive values such as arrays. There are also quite a few <a href=\"http://capsulephp.com/3.x/lazy.html\">lazy-resolution features</a> built in, as well as a <a href=\"http://capsulephp.com/3.x/providers.html\">definition provider</a> system.</p>\n<p>For a comparison with other autowiring DI containers, please see <a href=\"https://github.com/capsulephp/comparison\">capsulephp/comparison</a>.</p>\n<p>While Capsule does offer the ability to ...</p>\n<ul>\n<li>create, modify, retain, and return objects and values via autowiring;</li>\n<li>configure and define that creation, modification, and retention logic;</li>\n<li>inject those objects and values into their dependent objects; and,</li>\n<li>lazy-resolve values and objects at instantiation time;</li>\n</ul>\n<p>... it does not offer:</p>\n<ul>\n<li>\n<p><strong>Annotations.</strong> Annotations tend to couple a service to a particular\ncontainer implementation; I think that kind of coupling is wise to be avoid\non principle.</p>\n</li>\n<li>\n<p><strong>Caching and compiling.</strong> These are nominally performance enhancers, but in\nmy experience they are rarely necessary, and in those rare cases the\navailable speed increases are miniscule compared to other opportunities for\noptimization (e.g. database queries).</p>\n</li>\n<li>\n<p><strong>File-based configuration.</strong>  Capsule configuration is defined exclusively\nvia object-oriented PHP code, not via Neon/YAML/XML files or PHP arrays.\n(As a corollary, there is no special configuration notation to learn for\nCapsule, only class methods.)</p>\n</li>\n<li>\n<p><strong>In-flight container modification.</strong> This means you cannot set or reset new\nobject or value definitions once a Capsule container is instantiated.\n(There are ways to subvert this restriction, in which case you will get\nwhat you deserve.)</p>\n</li>\n<li>\n<p><strong>Invocation injection.</strong> Also called method-call injection or action\ninjection, I think this feature lies outside the scope of a DI/IOC system.</p>\n</li>\n<li>\n<p><strong>Tagging.</strong> I am ambivalent toward tagging; while I think it is little\noutside the scope of a DI/IOC system, I can see where others might find it\nuseful. Perhaps a future version of Capsule may include it.</p>\n</li>\n</ul>\n<p>These missing features may be deal-breakers for some developers, in which case\nthey have hundreds of autowiring and non-autowiring DI/IOC systems to choose\nfrom, including ...</p>\n<ul>\n<li><a href=\"https://github.com/auraphp/Aura.Di\">Aura</a></li>\n<li><a href=\"https://github.com/rdlowrey/auryn\">Auryn</a></li>\n<li>\n<a href=\"https://docs.laminas.dev/laminas-servicemanager/\">Laminas</a> (nee Zend)</li>\n<li><a href=\"https://laravel.com/docs/8.x/container\">Laravel</a></li>\n<li><a href=\"https://container.thephpleague.com/\">League</a></li>\n<li><a href=\"https://doc.nette.org/en/3.0/dependency-injection\">Nette</a></li>\n<li><a href=\"https://php-di.org/\">PHP-DI</a></li>\n<li><a href=\"https://symfony.com/doc/current/service_container.html\">Symfony</a></li>\n<li><a href=\"https://github.com/mindplay-dk/unbox\">Unbox</a></li>\n</ul>\n<p>... among other <a href=\"https://packagist.org/?query=dependency\">DI</a>\nand <a href=\"https://packagist.org/?query=ioc\">IOC</a> packages.</p>\n"
}
