You can specify component dependencies using the 'using' function as you 
know. As long as you know the key of the component in the system you can 
specify this dependency wherever you construct the component. If you want 
to parameterize dependencies, write a constructor function which takes the 
external dependency as a value. 

On Wednesday, March 11, 2015 at 2:17:12 PM UTC-4, Colin Yates wrote:
>
> I have a non-trivial component which requires a bunch of internal and 
> external collaborators to work. This component is itself re-usable. 
>
> What I really want to do is have ReusableComponent be a component in a 
> system so it can pull its external collaborators. However, 
> ReusableComponent constructs its own services etc. so it really want to be 
> (or at least have access to) a system.
>
> For example, let's say I have the following:
>
> (defrecord InternalToReusableComponent [bus]
>   (component/Lifecycle
>     (start [this]...))
>
> (defrecord ReusableComponent [bus logger]
>   (component/Lifecycle
>     (start [this]
>       
>       this)
>     ....))
>
> (defn reusable-component-system [external-collaborator]
>   (component/system-map
>     :bus (....)
>     :logger (....)
>     :reusable-component (component/using (map->ReusableComponent {}) [:bus 
> :logger external-collaborator]))
>
> Fine - I now have a system from which I can pull the reusable component. 
> However, where does 'external-collaborator' come from? Obviously there is a 
> larger system which I want this component to be part of so I can do:
>
> (defn larger-system []
>   (component/system-map
>      :external-collaborator (...)
>      :reusable-component (component/using (some-magic-glue) 
> [:external-collaborator])))
>
> I am struggling to see what (some-magic-glue) should be. I imagine it 
> needs to be something like:
>
> (defrecord SystemAdaptor [external-collaborator internal-system]
>   component/Lifecycle
>   (start [this]
>     (let [internal-system (or internal-system (reusable-component-system 
> external-collaborator))
>            internal-system (component/start internal-system)]
>      (assoc this :internal-system internal-system)))
>   (stop [this]
>     (let [internal-system (:internal-system this)
>            internal-system (component/stop internal-system]
>      (assoc this :internal-system internal-system)))
>
> but it all feels a bit yuck.
>
> I can't merge the two systems because the reusable component is chocka 
> full of very fine grained command handlers and both the internal and 
> external systems will have their own 'bus' for example. I could namespace 
> the keys but that again feels painful...
>
> Hope that is clear - and I look forward to your thoughts :).
>

-- 
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/d/optout.

Reply via email to