Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FactoryDescription protocol #33

Draft
wants to merge 32 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
log
Co-authored-by: Nikita Domnitskii <[email protected]>
  • Loading branch information
darkleaf and krevedkokun committed Jan 10, 2025
commit 00a302278c6f846e14fc26846cd69a0417b1068a
9 changes: 7 additions & 2 deletions src/darkleaf/di/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,8 @@
(fn [registry]
(fn [key]
(let [factory (registry key)]
(reify p/Factory
(reify
p/Factory
(dependencies [_]
(p/dependencies factory))
(build [_ deps]
Expand All @@ -905,7 +906,11 @@
(demolish [_ obj]
(p/demolish factory obj)
(after-demolish! {:key key :object obj})
nil))))))
nil)
p/FactoryDescription
(description [_]
(assoc (p/description factory)
::logged true)))))))


(defn- inspect-middleware []
Expand Down
16 changes: 16 additions & 0 deletions test/darkleaf/di/tutorial/x_inspect_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,19 @@
(di/inspect :env.long/PORT
(di/env-parsing :env.long parse-long)
{"PORT" "8080"}))))


(t/deftest log-test
(t/is (= [{:key ::di/implicit-root
:dependencies {`foo :required}
:description {::di/kind :ref
:key `foo
:type :required
::di/logged true}}
{:key `foo
:description {::di/kind :trivial
:object :obj
::di/logged true}}]
(di/inspect `foo
{`foo :obj}
(di/log)))))
Loading