TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Dependency Injection with Go

26 pointsby saj1thalmost 11 years ago

6 comments

argon81almost 11 years ago
Went down this path already.<p>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.<p>I discovered there are better and more idiomatic ways to do this type if thing without resorting to dependency injection.
评论 #8095706 未加载
评论 #8095741 未加载
评论 #8095772 未加载
chewxyalmost 11 years ago
Does anyone think this is a little stoppy (there isn&#x27;t a Go equivalent to &quot;unpythonic&quot;)?
评论 #8095640 未加载
评论 #8095646 未加载
mutatioalmost 11 years ago
&quot;Typically the main() function would call the various init functions like InitMongoService&quot;<p>Why muddy your main() when init() exists?<p>See: <a href="http://golang.org/ref/spec#Package_initialization" rel="nofollow">http:&#x2F;&#x2F;golang.org&#x2F;ref&#x2F;spec#Package_initialization</a>
评论 #8095709 未加载
fishnchipsalmost 11 years ago
I honestly don&#x27;t think there even was a problem to be solved. Constructors could just accept their dependencies (interfaces) as parameters.
评论 #8096385 未加载
pjmlpalmost 11 years ago
And thus the path to Go2EE slowly starts....
评论 #8095906 未加载
iandalmost 11 years ago
I&#x27;m interested in real examples of dependency injection being useful outside of hooking up testing objects. Anyone got any links to interesting examples?
评论 #8096236 未加载