Closed ieure closed 1 year ago
Integrant has a fairly narrow scope; it's not intended to be a generic configuration library, or to solve problems outside of managing dependencies.
You can use Aero with Integrant by adding an additional reader. I'm not too familiar with Aero, but something like this may work:
(defmethod aero/reader 'ig/ref [_ k v] (ig/ref k v))
(defmethod aero/reader 'ig/refset [_ k v] (ig/refset k v))
Say that I have some global configuration which I want to reference later:
I need the global
threads
value inside the:my.http/config
map, but there's no way to express this, because#ig/ref
only allows referencing top-level keys. This seems to leave two options, both of which seem unnecessarily complex:Break up
my.core/config
into separate top-level keys. For example:This is irksome, because I now have to define a bunch of
ig/init-key
methods for these keys, instead of one, which handles a map.Compute the config in
ig/init-key
. This requires overly complicated implementation of the:my.http/config
(and anything else needing global config into)ig/init-key
method. For example (roughly):Aero is able to ref arbitrary paths inside the EDN, but it can't be used with Integrant, since both libs have different reader macros. If the EDN contains
#ig/ref
, Aero fails to read it. The function-call form(ig/ref ...)
isn't evaluated, so lands in the config verbatim. Leaning solely on Aero's#ref
breaks Integrant's resolution -- the literal referenced config lands in the output, rather than the initialized output.The first approach seems like the least bad option. But I think that the real solution is for Integrant to support Aero-style deep references in
#ig/ref
.