Sierra's Component

77 views
Skip to first unread message

dieter.v...@gmail.com

unread,
Apr 6, 2024, 1:00:24 AMApr 6
to Clojure
Hello,  I'm playing a bit with the 'Component' library. The system has some initial configuration (port numbers, uri's, usernames,...) in code.

I'm doubting to eighter pass configuration when constructing the system:
(C/system-map
 :mycomponent  (map->MyComponent {:conf ...})

OR to pass configuration itself as a component
(defrecord Config ...)
(C/system-map
:config ...
:mycomponent
   (C/using (map->MyComponent ...) [:config])

Is there any reason why to prefer one way over the  other or is it just personal preference?

kind regards,
Dieter


Paul Stadig

unread,
Apr 6, 2024, 8:55:56 PMApr 6
to clo...@googlegroups.com
You can do either. If you pass the config as a dependency, then you have to access it in the `start` method after dependency injection has occurred.

Sometimes it is useful to write a constructor function to initialize the component. If that constructor needs access to the config it must be passed to the function, not provided as a dependency.

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/2abcf943-e885-4e17-9856-0247959115dcn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages