Thanks - I'd kind-of worked that out after posting (with the aid of a walk outside, and a beer!) but it's nice to know I'm on the right track. On 5 Jan 2014 19:05, "Stuart Sierra" <m...@stuartsierra.com> wrote:
> Hi Korny, > > Components implementing protocols can provide different implementations. > In the Database example, both the "real" component and the "stub" component > would have to implement some common protocol that defines the "primitive" > capabilities needed by the application. > > Traditional update-in-place databases are hard to mock, but I sometimes > stub a remote Datomic database with a local in-memory version. > > -S > > > > On Sun, Jan 5, 2014 at 1:23 PM, Korny Sietsma <ko...@sietsma.com> wrote: > >> Hi - I've been playing with this and I'm a little confused. >> >> I can understand how you use the library to pass around stateful >> components, and to start/stop them and wire them up etc. >> >> But I'm not sure I see how it should be used for more general dependency >> injection. >> >> I'll pick a concrete example - in the readme you have an ExampleComponent >> which calls "(get-user database :admin)" >> the "get-user" function then gets the connection from the Database >> component - but it's still coupled to the particular implementation of >> "execute-query": >> >> (defn get-user [database username] >> (execute-query (:connection database) >> "SELECT * FROM users WHERE username = ?" >> username)) >> >> If you wanted to unit test this function, you could pass whatever >> database connection thing you'd like - but you couldn't stub out the whole >> database, as execute-query is still coupled to the implementation of your >> database. More generally, anything that calls "get-user" will need to >> provide some sort of working database, or mock/stub out the call to >> execute-query, or the call to get-user itself. >> >> Is there something I'm missing? Is there some way you could/would do >> this with the component library? Or is this not the point of the library? >> >> - Korny >> >> >> >> On 21 November 2013 02:01, Stuart Sierra <the.stuart.sie...@gmail.com>wrote: >> >>> This is a small library/framework I've been working on for a few months. >>> >>> https://github.com/stuartsierra/component >>> >>> I use this to manage runtime state in combination with my "reloaded" >>> workflow using tools.namespace.[1] >>> >>> I've started using this on some personal and professional projects and >>> it seems to be working fairly well. >>> >>> >>> [1]: http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded >>> >>> -- >>> -- >>> 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. >>> >> >> >> >> -- >> Kornelis Sietsma korny at my surname dot com http://korny.info >> .fnord { display: none !important; } >> >> -- >> -- >> 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 a topic in the >> Google Groups "Clojure" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/clojure/jXnxVZaP2K4/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> clojure+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/groups/opt_out. >> > > -- > -- > 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. > -- -- 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.