Hi Colin,
On 5/10/13 5:04 AM, Colin Yates wrote:
1) to use (defonce *data-source*...) so that every body who requires
that ns gets the same instance?
While this has been done I view this as an antipattern. The big problem
with this approach is that you now can only have a single *data-source*
for your entire application. Testing becomes hard, stopping and
restarting is difficult, etc... While this approach is easy the
resulting workarounds introduce incidental complexity.
2) to provide a 'get-ds' accessor which returns a new instance and
rely on passing that service along to every function that needs it?
Propagating the dependency like this is as much as an antipattern in
Clojure as it is in OO languages[1] IMO. As you point out it is also
just as much fun. :)
3) some other way I don't know about
The way I've been doing DI like stuff is with Prismatic's graph[2] and
similar libraries. While graph doesn't explicitly say it is a DI
library it certainly is solving the same problem. What is interesting
about graph is how small it is and how it can solve problems in the
large (like an application) but also on a much smaller scale (e.g.
computations with a handful of functions). While graph's approach may
not be as powerful as the huge DI frameworks in Java (I'm assuming, I
haven't used them personally much) I think you can get 90% of the value
with 1% of the code. I've been using a graph-like library for a number
of months in my more complex applications and it has been fantastic.
HTH,
Ben
1. http://picocontainer.codehaus.org/propagating-dependency-antipattern.html
2.
http://blog.getprismatic.com/blog/2012/10/1/prismatics-graph-at-strange-loop.html
https://github.com/Prismatic/plumbing
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.