weavejester / integrant

Micro-framework for data-driven architecture

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

is it possible to access a component after it's init-key, but before it gets passed to the next key that depends on it?

BlanceXR opened this issue · comments

For example, say I have 2 keys

(defmethod ig/init-key ::config [_ _] 
  (aero/read-config "config.edn"))  ;; => {:db-config {...}, :other-config ...}

(defmethod ig/init-key ::db [_ {:keys [db-config]}]
  (db-init db-config))

in this case, ::db needs db-config, but db-config is inside of the ::config
to make it work, I need to either have ::db take in the whole config, and then extract :db-config from it,
or to create another key, which takes a whole config, and emits a db-config.

both options are not ideal IMO.

i'd hope to do something like:

{::config {}
 ::db {:db-config (get (ig/ref ::config) :db-config)}}

which apparently won't work since ig/ref is just a ref before it's actually initialized.

prep-key won't cut it either as it technically belongs to ::db as well, which shouldn't know the whole system config being passed around.
also prep-key would prep a key universally, where in a monorepo, I could have different ns trying to init the same :core/db for example, but they'd want to prep db differently based on how their config file structure look like

any suggestion?

btw, do you typically make a system config into a component?

In this situation, I'd read the configuration and incorporate it into the config map before initiation. So:

(-> config
    (merge (aero/read-config "config.edn"))
    (ig/init))

I see, so don't treat system config as a component, but as something that's used to build the ig-config, thanks