I am trying to setup a simple integrant config, but the compiler chokes in the #ig/ref tag - what am I missing? Thx… `(ns hello-integrant.hi-test (:require [integrant.core :as ig] [clojure.edn :as edn])) (def config {[:attrs :test] {:attr1 “attr1-val”} [:hello-integrant.hi-test/test-data :read] {:path “resources/test_data.edn”} [:hello-integrant.hi-test/test-data :def] {:data #ig/ref [:hello-integrant.hi-test/test-data :read] :attrs #ig/ref [:graph-attrs :test]}}) (defmethod ig/init-key [:attrs :test] [_ {:keys [attrs]}] attrs) (defmethod ig/init-key [::test-data :read] [_ {:keys [path]}] ;;don’t slurp path for now {:mydata :anything}) (defmethod ig/init-key [::test-data :def] [_ {:keys [data attrs]}] (println :DATA data :ATTRS) (def data-map {:d data :a attrs})) `
@kingcode Use (ig/ref :blah)
instead. The #ig/ref
tag is added to the ig/read
function, but not to data_readers.clj
.
Also be aware that keywords without namespaces can’t be derived in Clojure, so all keys in the configuration must be namespaced.
@weavejester Thank you very much for the advice, and for your great work!….(ig/ref ..) worked, but I had other issues which led me to this one…I probably will have more questions 🙂
No problem. I’ll be sitting in this channel for a while yet.
@weavejester indeed, it looks like my other issue is namespaced-keyword related, will try your suggestion..
Also, the keys used in init-key
have to be a single keyword I believe.
@weavejester ah, that’s what it is then - I was using [:ns1/kw1 :ns2/kw2] dispatch values in my defmethods: 1. Caused by java.lang.IllegalArgumentException No method in multimethod ‘init-key’ for dispatch value: :integrant.composite/hackenbush.graph-attrs+hackenbush.test_21739
@weavejester so it is necessary to use derive to leverage compound keys in the config?
Composite keys are just a shortcut for using derive.
So this:
{[::foo ::bar] {}}
Ah OK thx…I didn’t assimilate the use of derive to achieve that yet….will look into it.
Is equivalent to:
(derive ::foo+bar ::foo)
(derive ::foo+bar ::bar)
{::foo+bar {}}
@weavejester thank you much! Great videos also…thx
Thanks 🙂