Hi Torsten,

It works best when it is all-or-nothing, so the caller of get-user
would itself be a component that is dependant upon the db component.

The way I visualise it is that the components are a very thin layer at
the outer edge of the system that delegate to actual worker functions.
Those worker functions need something (e.g. a database) and so a
component is created which simply unravels the dependencies.

How do the worker fns actually get called - the dispatching is up to
you - I tend to have a bus (or channel) which is the glue underneath
the gateway.

For example, I might have:
 - a command bus which needs a command registry
 - a number of handlers which each handle a command

I might have:
 - a CommandRegistry component which exposes the actual registry
 - a CommandOneHandler component which depends on the registry and
registers command-one-handler as the handler of CommandOne. It might
actually register a (partial command-one-handler collab-1 collab-2
etc.)
 - a CommandDispatcher component which takes the command registry,
listens to commands and then dispatches to the correct handler

Hope that helps.




On 15 March 2015 at 15:55, Torsten Uhlmann <[email protected]> wrote:
> Hi Walter,
>
> thanks for the quick reply.
>
> Now, what does the other side of the call look like, where does the caller
> of "get-user" get the database component from? That's what I don't get.
>
> Thanks,
> Torsten.
>
> Am Sonntag, 15. März 2015 16:51:51 UTC+1 schrieb Walter van der Laan:
>>
>> Hi,
>>
>> This is an example from http://github.com/stuartsierra/component
>>
>> (defn get-user [database username]
>>   (execute-query (:connection database)
>>     "SELECT * FROM users WHERE username = ?"
>>     username))
>>
>>
>> Here 'database' is a component which is passed to 'get-user' as an
>> argument. The component can be used just like any other hashmap, so
>> (:connection database) gets the database connection.
>>
>> On Sunday, March 15, 2015 at 4:20:35 PM UTC+1, Torsten Uhlmann wrote:
>>>
>>> Hi,
>>>
>>> I'm tapping my toes in component land and I think I lack some conceptual
>>> understanding, probably done too much OO.
>>> Please forgive me if this is a stupid question (and I get a feel that it
>>> is)...
>>>
>>> Suppose I create a Lifecycle component with some state, say, a database
>>> component that creates a connection on calling "start".
>>> That connection is assoc'ed into the component map.
>>>
>>> Now, how do I access the database component map when I want to call
>>> functions that use the connection?
>>> These functions are defined outside the defrecord of the component, how
>>> do they get access to the map?
>>>
>>> I could access the system var (the one that holds the system for
>>> development purposes) or save it into an atom, but I don't really think that
>>> would be a good approach?
>>>
>>> Thanks,
>>> Torsten.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to