{"id":15010331,"url":"https://github.com/chunsen-w/clojure-di","last_synced_at":"2025-12-24T20:43:15.855Z","repository":{"id":231326119,"uuid":"781486194","full_name":"chunsen-w/clojure-di","owner":"chunsen-w","description":"A clojure library to help manage app state, and the dependency graph, like DI libraries for java","archived":false,"fork":false,"pushed_at":"2025-08-21T15:43:01.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-24T07:56:36.649Z","etag":null,"topics":["clj","clojure","dependency-injection","di","state-management"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chunsen-w.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-03T13:27:54.000Z","updated_at":"2025-08-21T15:42:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"51d08efe-0dae-48ab-9e00-0549125bffe0","html_url":"https://github.com/chunsen-w/clojure-di","commit_stats":null,"previous_names":["chunsen-w/clojure-di"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/chunsen-w/clojure-di","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chunsen-w%2Fclojure-di","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chunsen-w%2Fclojure-di/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chunsen-w%2Fclojure-di/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chunsen-w%2Fclojure-di/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chunsen-w","download_url":"https://codeload.github.com/chunsen-w/clojure-di/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chunsen-w%2Fclojure-di/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28008433,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-24T02:00:07.193Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clj","clojure","dependency-injection","di","state-management"],"created_at":"2024-09-24T19:33:35.482Z","updated_at":"2025-12-24T20:43:15.850Z","avatar_url":"https://github.com/chunsen-w.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Clojars Project](https://img.shields.io/clojars/v/com.github.chunsen-w/clj-di.svg)](https://clojars.org/com.github.chunsen-w/clj-di)\n\n## The basic idea\nFor a function, take it's arguments as dependencies, which will be injected automatically by the framework. And the return map as values it can provie to the injection context.\n\nEg:\n```clojure\n(defn a-fun [{:keys [db-port db-url]}]\n  {:db-connection some-conn})\n```\nFor this demo function, it means that give a `db-port` and a `db-url`, it will generate connection, and this connection can be injected by other functions with `db-connection`\n\n## How to use\n### Baic usage\n```clojure\n(require '[com.github.clojure.di.core :refer [defdi execute]])\n\n(defdi http-server [{:keys [http-port route]\n                     db-conn :db-connection}]\n  ;start http server\n  {:http-server xxx})\n\n(defdi database [{:db/keys [url port user password]}]\n  ; create db connection\n  {:db-connection the-connection}）\n\n;; other di\n(defdi ...)\n\n;;then run the di by\n(execute [http-server database ...])\n```\n`defdi` has the same syntax as `defn`, and returns a normal function just as `defn`, except   \n  1. It must have exactly one or zero argument\n  2. It must return a map with keyword as keys\n\nThen by run `(execute [http-server database ...])`,  it will calculate the dependency graph, and excute the di functions one by one with their dependency order\n\n### Use `bootstrap`\nFor convenience, this library also provide a `bootstrap` function, to help you bootstrap you application \n```clojure\n(require '[com.github.clojure.di.app :refer [bootstrap]])\n\n(bootstrap \"com.example\")\n```\nThen, the libary will scan all the namespace in the classpath which has the prefix `com.example`, and collect all the di component defined by `defdi`, and excute them.   \n\n*Thus, you don't need to care about where to import the depenedency, just let the library to handle it* \n\nFor more detail usage, refer the [tests](https://github.com/wangchunsen/clojure-di/blob/main/test/com/github/clojure/di/core_test.clj)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchunsen-w%2Fclojure-di","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchunsen-w%2Fclojure-di","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchunsen-w%2Fclojure-di/lists"}