weavejester / integrant

Micro-framework for data-driven architecture
MIT License
1.22k stars 63 forks source link

No method in multimethod 'init-key' for dispatch value #98

Closed lensgolda closed 2 years ago

lensgolda commented 2 years ago

Hi James, a bit confused about i'm open this issue, have tried to play with keys and namespaces, but nothing happened, so i don't understand what i'm doing wrong. Can you help please. (maybe something with namepaces and keys)

Have an issue with no method while dispatching value

Execution error (IllegalArgumentException) at integrant.core/try-build-action (core.cljc:294).
No method in multimethod 'init-key' for dispatch value: :family.bot.providers.weather/weather-api-com

I've found same issue in duct, but looks like not my case, because haven't used any tool, plugins, config merges, only plain config edn with aero/read-config, and extending 'ig/ref for aero) Everything works fine from repl, and issue happens only for uberjar or when running with deps cli -main method like so

clj -M -m family.bot.core or java -cp target/family-bot-standalone.jar clojure.main -m family.bot.core

project.clj

:main ^{:skip-aot true} family.bot.core
:profiles {:uberjar {:aot :all}}

config.edn

{:family.bot.services.scheduling/weather       {:provider  #ig/ref :family.bot.providers.weather/weather-api-com
 :family.bot.providers.weather/weather-api-com {:key      #env WEATHER_API_KEY
                                                :base-url "http://api.weatherapi.com/v1/forecast.json?q=London&aqi=no"}}

namespace

(ns family.bot.providers.weather.weather-api-com
...
(defmethod ig/init-key :family.bot.providers.weather/weather-api-com
  [_ config]
  (map->WeatherApiCom config))

main ns

(ns family.bot.core
  (:require [integrant.core :as ig]
            [aero.core :as aero])
  (:gen-class))

(defmethod aero/reader 'ig/ref
  [_ _ value]
  (ig/ref value))

(defn -main
  [& args]
  (let [config (aero/read-config "config/config.edn")]
    (ig/init
      config
      [:family.bot.services.scheduling/weather])))

All code can be found here

weavejester commented 2 years ago

There's nothing in your code that loads the family.bot.providers.weather.weather-api-com namespace. You want to either use load-namespaces or require the namespace manually.

lensgolda commented 2 years ago

yep, already fix that with ig/load-namespaces, didn't think that ig/load-namespaces required. Unfortunately it's not so obvious from the docs beginning, where

(def system
  (ig/init config [:adapter/jetty]))

and i was using load-namespaces in my repl stuff documentation, so it worked well.

Thanks! You can close issue. P.S. Glad if my inattention will be helpful for anyone :)