integrant

nblumoe 2017-12-21T08:29:22.000227Z

Hi, is there a way to have conditional service dependencies, e.g. exclude a service based on env variables?

2017-12-21T08:40:17.000346Z

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.

nblumoe 2017-12-21T10:01:12.000213Z

Yes, exactly. I wonder though if there is some kind of support in integrant to do this declaratively in the system config map.

nblumoe 2017-12-21T10:05:30.000476Z

[{: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 set

2017-12-21T10:13:17.000249Z

Ah, 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).

2017-12-21T10:16:21.000386Z

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}})

2017-12-21T10:21:01.000020Z

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)))

nblumoe 2017-12-21T10:52:28.000253Z

Thanks. That is what I was expecting. Thanks a lot! 🙂