Re:Dependency Injection with Go
by nostrademons on Monday July 28, 2014 @05:22AM
(#8095825)
They're trying to pass the objects created at startup into other objects, so that dependencies are explicit and can be mocked out in unit tests. You can't do this with init(), which always takes no arguments and returns no values.
> I was referring to Go's magic func init()
I know you were; I'm arguing that components shouldn't need an explicit initialization step, but rather they should be initialized as part of their `NewFoo` constructor.
Putting that in your files, let's say:
All fired automatically prior to your applications main() entry point WITHOUT needing to pollute main() with initDB(); initTemplates(); initSettings() etc. etc.