Derived Keys Reference Behaviour
omartell opened this issue · comments
Hi there,
I am trying to rely on derived keywords to be able to start the system with or without db connection pooling. The configuration I have implemented is the following:
(def system
{[:system.db/db :system.db/pool] {:jdbc-url (:jdbc-url config)}
[:system.db/db :system.db/conn] {:jdbc-url (:jdbc-url config)}
:system.service/service {::http/port (:http-port config) :db (integrant/ref :service.db/db)}})
I also have the respective multimethod implementations for :system.db/pool
and :system.db/conn
.
However, when I try to start the system with just a set of keys I get an Ambigous key
exception:
(integrant/init system [service.db/conn system.service/service])
Shouldn't that work? It seems to me that should work as I am actually specifying what implementation to use. Just a thought.
Thank you
The problem is that the dependency graph needs to be resolved first. For example, assume you had a configuration:
(def config {::foo 1, ::bar (ig/ref ::foo)})
And started it with:
(ig/init config [::bar])
Integrant resolves the dependency graph, which tells is that ::bar
depends on ::foo
, and therefore both keys should be initiated.
With an ambiguous key the dependency graph cannot be resolved, so init
cannot continue. In your case you could fix this just by dissoc
ing the key that isn't required, or by adding a pre-processing step before init
is called.