juxt / aero

A small library for explicit, intentful configuration.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting an unexpected circular dependency

kgxsz opened this issue · comments

commented

After looking at the example of #ref in the README.md I tried using it in my own config as follows:

{:some-top-level-key {:db-connection "datomic:dynamo://dynamodb"
                      :webserver {:db #ref [:some-top-level-key :db-connection]}}

This gives a circular dependency error.

Anything I'm missing here? Is #ref only valid if the path to the #ref doesn't share any of the path defined in the #ref vector?

Thank you :)

That's correct. It's possible that in some cases we could navigate this by detecting literals, but it's a difficult problem to solve generally.

Consider a case where #profile or #domain is in use, you have to know that #profile needs turning into a value before the #ref for you to get the expected results.

commented

I see, I suppose this encourages use of a shallower configuration map?

I'd generally recommend you do:

{:db/connection "datomic:dynamo://dynamodb"
 :my-component {:db-connect #ref [:db/connection]
                :webserver {:db #ref [:db/connection]}}

Not necessarily shallower, but you have to abstract out adjacent keys in nested maps. I've not run into a case where this hasn't actually pointed out that I've tied two things together more than they need to be, but I still believe such a case exists.

commented

👍