-
-
Save KingCode/75026a8bdae9415e773a25f0aac99e5d to your computer and use it in GitHub Desktop.
When the config is in a file, (ig/ref ...) doesn't get evaluated in the dependent method- see core.clj below. It works as expected when config is a literal (see core2.clj)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:hello-integrant/data | |
{:my-data {:a 1 :b 2}} | |
:hello-integrant/consumer | |
{:id 1 | |
:param (ig/ref :hello-integrant/data)}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns hello-integrant.core | |
(:require [integrant.core :as ig])) | |
(defmethod ig/init-key :hello-integrant/data [_ {:keys [my-data]}] | |
my-data) | |
(defmethod ig/init-key :hello-integrant/consumer [_ {:keys [id param]}] | |
(println :ID id :PARAM param) | |
param) | |
(def config (ig/read-string (slurp "src/hello_integrant/config.edn"))) | |
(ig/init config) | |
;; => :ID 1 :PARAM (ig/ref :hello-integrant/data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns hello-integrant.core2 | |
(:require [integrant.core :as ig])) | |
(def config {:hello-integrant/data | |
{:my-data {:a 1 :b 2}} | |
:hello-integrant/consumer | |
{:id 1 | |
:param (ig/ref :hello-integrant/data)}}) | |
(defmethod ig/init-key :hello-integrant/data [_ {:keys [my-data]}] | |
my-data) | |
(defmethod ig/init-key :hello-integrant/consumer [_ {:keys [id param]}] | |
(println :ID id :PARAM param) | |
param) | |
(ig/init config) | |
;; => :ID 1 :PARAM {:a 1, :b 2} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment