DI is a dependency injection framework that allows you to define dependencies as easily as you define function arguments.
It uses plain clojure functions and associative destructuring to define a graph of functions and stateful objects.
(ns app.core
(:require
[darkleaf.di.core :as di]
[ring.adapter.jetty :as jetty]
[app.adapters.reitit :as-alias reitit]
[app.adapters.hikari :as-alias hikari]
[app.adapters.db :as-alias db]))
(defn show-user [{ds ::db/datasource} req]
...)
(def route-data
(di/template
[["/users/:id" {:get {:handler (di/ref `show-user)}}]]))
(defn jetty
{::di/stop (memfn stop)}
[{handler ::handler
port :env.long/PORT
:or {port 8080}}]
(jetty/run-jetty handler {:join? false, :port port}))
(di/start `jetty
(di/env-parsing :env.long parse-long)
{::handler (di/ref `reitit/handler)
::reitit/route-data (di/ref `reitit/data)
::db/datasource (di/ref `hikari/datasource)
"PORT" "9090"})It is just a short snippet, please see example app.
{:deps {org.clojars.darkleaf/di {:mvn/version "%TAG%"}}}
;; or
{:deps {org.clojars.darkleaf/di {:git/url "https://github.com/darkleaf/di.git"
:sha "%SHA%"}}}Full documentation, tutorials, and API reference are available on cljdoc.
See also the example app, starting with user.clj.
- See
1.0branch for previous version - See
masterbranch for current version
Copyright © 2022 Mikhail Kuzmin
Licensed under Eclipse Public License v2.0 (see LICENSE).