from Hacker News

Dependency Injection with Go

by saj1th on 7/28/14, 7:03 AM with 24 comments

  • by argon81 on 7/28/14, 8:16 AM

    Went down this path already.

    It was OK for a while with a small codebase, but the problem is that you need to give up your simple direct Go code for magic reflection.

    I discovered there are better and more idiomatic ways to do this type if thing without resorting to dependency injection.

  • by chewxy on 7/28/14, 7:32 AM

    Does anyone think this is a little stoppy (there isn't a Go equivalent to "unpythonic")?
  • by mutatio on 7/28/14, 7:57 AM

    "Typically the main() function would call the various init functions like InitMongoService"

    Why muddy your main() when init() exists?

    See: http://golang.org/ref/spec#Package_initialization

  • by fishnchips on 7/28/14, 12:23 PM

    I honestly don't think there even was a problem to be solved. Constructors could just accept their dependencies (interfaces) as parameters.
  • by pjmlp on 7/28/14, 9:50 AM

    And thus the path to Go2EE slowly starts....
  • by iand on 7/28/14, 12:07 PM

    I'm interested in real examples of dependency injection being useful outside of hooking up testing objects. Anyone got any links to interesting examples?