If you haven't already then you might want to watch:
https://www.youtube.com/watch?v=13cmHf_kt-Q
If it helps:
(defn a-real-worker [db]
...)
(defrecord ARealWorkerComponent [db registry]
components/Lifecycle
(start [this]
(registry-api/register registry (partial a-real-worker-fn db))
this)
(stop [this]
....)))
(defn a-real-worker-component []
(map->ARealWorkerComponent {}))
;; in the layer above these components
(def system (components/systemmap
:db (infrastructure/new-db)
:a-real-worker (components/using
(a-real-worker-api/a-real-worker-component)
[:db])) ;; THIS IS WHERE IT GETS WIRED UP
So the real work is done in a-real-worker but it needs collaborators.
It does that with ARealWorkerComponent (which probably also registers
(a-real-worker...) with a registry of some sort.
When you call start the library will parse the 'using' meta-data to
provide the dependencies the component needs.
Your question of how to actually *call* a-real-worker depends on your
dispatching. Check out https://github.com/danielsz/system for some
examples of using ring handlers for example.
HTH
On 15 March 2015 at 17:30, Torsten Uhlmann <[email protected]> wrote:
> Colin,
>
> thanks for the thoughtful explanation!
>
> I still have a problem understanding the flow. Say I want to call a
> component function (like "get-user") from another component that depends on
> the database component.
>
> I still don't understand how a component function accesses it's
> dependencies? There is the Lifecycle record that gets passed the
> dependencies, constructs the component and returns a new map in the start or
> stop function. But any function of that component is not defined inside the
> scope of defrecord (correct ?) and the component map. So how would that
> function access its own dependencies.
>
> I have the feeling that this problem comes from some very basic
> misunderstanding on my end. Something very basic I'm missing.
>
> 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.