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.

Poor man's dependency injection in Clojure

39 pointsby pyritschardover 11 years ago

4 comments

eigenrickover 11 years ago
This is just my opinion, but if one is writing dependecy-injected frameworks in Clojure, then they're missing the point of Clojure.
评论 #7120997 未加载
评论 #7120891 未加载
评论 #7120935 未加载
评论 #7121471 未加载
Qerubover 11 years ago
The one-function protocols strike me as unidiomatic; why not use functions directly? `(fn […] …)` would work just as well as `(reify P (f [this …] …))` (`this` is never used).<p>Update: I looked at the code again and noticed that `stdin-transport` implements <i>two</i> protocols. Guess I need to think a little bit more about this.
moominover 11 years ago
Check out Stuart Sierra&#x27;s &quot;component&quot; for another take. Of course, another take is that you&#x27;re better off just constructing objects by calling their constructors directly.
评论 #7120920 未加载
gengstrandover 11 years ago
A chapter from the O&#x27;Reilly book covers this subject pretty well. With Clojure&#x27;s java interop, you can still use Spring. Thanks to the homoiconicity of the language, support for higher order functions, and with some clever use of Clojure&#x27;s load-file function in core, you kind of get DI baked into the language for free.