I've been reading up a lot on Dependency Injection, Inversion of Control, and IoC containers. I also primarily program in dynamic languages (PHP at work, Python at home). Here are the things I'm finding, but this leaves a lot of gaps for me to fill as I piece it all together:
So what I'm reading is: IoC containers are a much bigger deal in static languages, because it's so much easier to perform DI in dynamic languages. But they also provide benefits far beyond DI, like managing dependencies for you and saving you from having to string together a dozen objects by hand. And, incidentally, they are complicated, so don't try to do them yourself (but no good ones exist for PHP).
I feel like this information leaves me kind of... stuck. What do I do with it? I work in a very large codebase, with very complicated dependencies (and probably a strong need for refactoring, but that's another parallel issue). We've done very poorly at implementing DI up till now, and I'm really trying to turn us in the right direction. There just seems to be nothing out there in regards to dynamic languages and IoC (or at least IoC containers).
Am I better off "hand-stringing" dependencies together for the time being, and worry about automating it in a container later, after I get a better handle on the principles? Is it worth implementing my own simple IoC container? Or is the benefit just not ultimately worth the cost in PHP?
For PHP try Symfony Dependency Injection. It's (supposedly - I've too little experience to validate that) based on how Java Spring works, but using a lot of PHP 'magic' too. AS a result it's quite lightweight and easy to use, while being able to do quite a lot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With