How does one inject state into ring handlers most conveniently (without using global vars)?
Here is an example:
(defroutes main-routes
(GET "/api/fu" [] (rest-of-the-app the-state)))
(def app
(-> (handler/api main-routes)))
I would like to get the-state
into the compojure handler for main-routes
. The state might be something like a map created with:
(defn create-app-state []
{:db (connect-to-db)
:log (create-log)})
In a non ring application I would create the state in a main function and start injecting it, or parts of it, as function parameters to the different components of the application.
Can something similar be done with ring's :init
function without using a global var?