Hi, I’m using composite keys, and they work very well for my overall use-case, but then I noticed that cleanup is not straight forward as they produce nil components. Using example from README as illustration:
{[:adapter/jetty :example/web-1] {:port 8080, :handler #ig/ref :handler/greet}
[:adapter/jetty :example/web-2] {:port 8081, :handler #ig/ref :handler/greet}
:handler/greet {:name "Alice"}}
Here, I assume that :adapter/jetty is another entry in the system config map with a corresponding (defmethod ig/init-key :adapter/jetty ... while :example/web-1 and :example/web-2 does not have entries in the system config map or ig/init-key dispatches. Hence, practically working as component IDs for two Jetty instances. My understanding is backed by the fact that Integrant does not complain about missing init-key dispatch for the two.
Then to the point:
Assuming that :adapter/jetty returns a Jetty server instance, I was expecting the two composites to do the same, but looking at my running system instance, all composite keys have nil values/components.
For my running system this is does not matter right now, but it very much affects the ability for cleanup with ig/halt-key!as it gets passed <key> and nil as args.
Is this expected behaviour, a bug, or is there some misunderstanding on my part?No problem! I know all about sporadic Slack usage, as you can probably tell from me taking 4 days to respond 🙂
That's unexpected, but I can't reproduce your results in 0.8.1:
user=> (require '[integrant.core :as ig])
nil
user=> (defmethod ig/init-key ::foo [_ v] {:active v})
#object[clojure.lang.MultiFn 0x722a439 "clojure.lang.MultiFn@722a439"]
user=> (ig/init {[::foo ::example] 1})
{[:user/foo :user/example] {:active 1}}
Can you provide an example repository, or some way I can reproduce this issue?Sorry about the late response. I’m a sporadic Slack user and assumed there would be a notification. I then forgot all about it after moving on to other tasks.
Anyway, your response and maybe having not looked at the code for a while, made me spot my error quickly. A bit embarrassing, but the map that was supposed to make up the component, turned out to be enclosed in a doseq used to wire things up. I got the expected result when I moved it outside.
Thanks for taking the time to respond and for the library as well. I find that its design and mental model suits me better than another alternative I’ve used.