5 ms·
> dependency injection It's been a while since I played with the furry thing but is that even possible in Golang?
by limit499karma 2y ago
> dependency injection
It's been a while since I played with the furry thing but is that even possible in Golang?
- pjmlp 2y agoI was speaking about Python, Java and .NET standard libraries. In Go you can naturally do it, by using the manual constructor approach, however there is no magic auto wiring like you can do with attributes and compiler plugins, plus standard libraries infrastructure for locating services, from those three ecosystems above.
- limit499karma 2y agoWell, in my head DI at this point requires the magic bits. Otherwise it is (as you say) just constructor args.
- pjmlp 2y agoExcept that there are many ways to do DI, magic is not necessarly required, other than much welcomed development experience. However Go doesn't like magic, thus that isn't something that will ever happen on the standard library, like on Python, Java, .NET.
- limit499karma 2y agoI guess we have to disagree here. The key word here is "injection". Dependency initialization, setting, passing, etc. none of these are 'injection'. But yes, Go lacks the necessary metadata mechanisms and per what you are saying it still does.
- pjmlp 2y agoInjection doesn't mean automatic, or magic. And if one goes back 20 years, constructor based injection was the norm, the magic only came later thanks to Aspect Oriented Programming, yet another tool that Go will never adopt.
- limit499karma 2y agoSure, but I don't recall it being called "injection". Obviously we are in agreement that dependency references are introduced via some mechanism. Also AOP came [after] Java J2EE and Spring. However I will concede that there is a distinction between 'inversion of control' and general DI.