Liking cljdoc? Tell your friends :D

Multi system

(ns darkleaf.di.tutorial.z-multi-system-test
  (:require
   [clojure.test :as t]
   [darkleaf.di.core :as di]))

In some cases, you may need multiple systems and to share a subsystem between them. In that case, just pass the subsystem in the registry.

To get a value of the subsystem, you should deref it as you would for a regular system root. Also you should manually stop systems in reverse order.

(defn shared
  {::di/kind :component}
  []
  (Object.))

(defn server
  {::di/kind :component}
  [{name   ::name
    shared `shared}]
  [name shared])

(t/deftest multi-system-test
  (with-open [shared (di/start `shared)
              a      (di/start `server {`shared @shared
                                        ::name  :a})
              b      (di/start `server {`shared @shared
                                        ::name  :b})]
    (t/is (= :a (first @a)))
    (t/is (= :b (first @b)))
    (t/is (identical? (second @a) (second @b)))))

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close