Hi, is there a way to have conditional service dependencies, e.g. exclude a service based on env variables?
Not sure exactly what you mean, could you perhaps provide an example? My guess, though, is that it would come down to manipulating the config map in some way.
Yes, exactly. I wonder though if there is some kind of support in integrant to do this declaratively in the system config map.
[{:my.system/comp-a {my.system/comp-b #integrant/ref[my.system/comp-b]} ;;; only depend on comp-b if an env variable is set
:my.system/comp-b {:some-data 1234}}]
In that example I would like to have no dependencies on comp-a
if an env variable is not set, but have the dependency on comp-b
when it is setAh, I see. I'm pretty sure there's no way to do this declaratively in a .edn
file (the only addition integrant makes to edn is #ref
which can only read a keyword).
If you put your config in a .clj
file you can use Clojure to do stuff conditionally, though:
(def config
{:my.system/comp-a {:my.system/comp-b (when (env :should-include-comp-b?)
(ig/ref :my.system/comp-b))}
:my.system/comp-b {:some-data 1234}})
You could also keep it declarative in the edn file and then manipulate it after reading:
(ig/init (cond-> (ig/read-string edn-string)
(env :should-not-include-comp-b?) (update :my.system/comp-a dissoc :my.system/comp-b)))
Thanks. That is what I was expecting. Thanks a lot! 🙂