Re: [ANN] Component: dependency injection and state management
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.comwrote: 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 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.
Re: [ANN] Component: dependency injection and state management
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.comwrote: 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.
Re: [ANN] Component: dependency injection and state management
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.comwrote: 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
Re: [ANN] Component: dependency injection and state management
This is simple brilliant... The approach proposed and the component framework implementing it finally solves the issue with the necessary evil (start/stop interactions with statefull components in any bigger Clojure app) by cleverly taking only the best ideas (like using inferred dependency graph to automatically start/stop components in the correct order) from Java DI frameworks like Spring, which i have a lot of experience with. Thank you very much for this work. Dňa štvrtok, 21. novembra 2013 3:01:19 UTC+1 Stuart Sierra napísal(-a): 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.
Re: [ANN] Component: dependency injection and state management
Hi, great work indeed. One question though: Why do you prefer declaring dependencies between components of a system explicitly instead of using prismatics Graph? On Thursday, November 21, 2013 3:01:19 AM UTC+1, Stuart Sierra 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.
Re: [ANN] Component: dependency injection and state management
On Thu Nov 21 07:14:16 2013, Stuart Sierra wrote: On Thursday, November 21, 2013 7:22:10 AM UTC-5, abp wrote: Why do you prefer declaring dependencies between components of a system explicitly instead of using prismatics Graph? 'Graph' by itself does not preserve the dependency relationships after constructing the map. But the two approaches are not incompatible: you can use 'Graph' to construct the system map, then use 'Component' to manage it. -S If you are interesting in taking that approach you can use my system-graph which does just that: https://github.com/RedBrainLabs/system-graph I spoke with Stuart at the conj about this library and I realized that system-graph it is currently relying on an implementation detail in order to work. I haven't had any issues with it but I can see places where it will not work. I plan on fixing this issue so the proper 'Component' metadata is attached to the system-graph. When I do that I'll release v0.2.0. -Ben -- -- 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.
Re: [ANN] Component: dependency injection and state management
On Thursday, November 21, 2013 7:22:10 AM UTC-5, abp wrote: Why do you prefer declaring dependencies between components of a system explicitly instead of using prismatics Graph? 'Graph' by itself does not preserve the dependency relationships after constructing the map. But the two approaches are not incompatible: you can use 'Graph' to construct the system map, then use 'Component' to manage it. -S -- -- 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.
[ANN] Component: dependency injection and state management
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.