Defines how to build a single object that di can wire into a system.
Most users don't implement Factory directly — defn plus the
built-in ref/template/derive helpers cover the common cases.
Implement it when a key needs custom resolution that those can't
express.
The runtime queries dependencies first, then calls build with
the resolved values.
Defines how to build a single object that di can wire into a system. Most users don't implement `Factory` directly — `defn` plus the built-in `ref`/`template`/`derive` helpers cover the common cases. Implement it when a key needs custom resolution that those can't express. The runtime queries `dependencies` first, then calls `build` with the resolved values.
(build this dependencies add-stop)Returns the built object.
dependencies is a map {key built-object} for the keys declared
by (dependencies this). Required keys hold a non-nil value.
Optional keys may be nil.
add-stop registers a zero-arg cleanup procedure to run on system
shutdown. Call (add-stop f) once per resource you allocate.
Registered cleanups run in LIFO order.
Returns the built object.
`dependencies` is a map `{key built-object}` for the keys declared
by `(dependencies this)`. Required keys hold a non-nil value.
Optional keys may be `nil`.
`add-stop` registers a zero-arg cleanup procedure to run on system
shutdown. Call `(add-stop f)` once per resource you allocate.
Registered cleanups run in LIFO order.(dependencies this)Returns one of:
{key dep-type} of the factory's dependencies[key dep-type] pairs (preserves build order —
useful when builds carry side effects like migrations)nil or {} for no dependenciesA key is a symbol (var), a keyword (abstract), or a string (env
var). A dep-type is :required or :optional:
:required — the key must resolve to a non-nil object, otherwise
di/start fails with ::di/missing-dependency.:optional — build receives nil for this key if it doesn't
resolve.May be called multiple times per di/start. Should be pure.
Returns one of:
- a map `{key dep-type}` of the factory's dependencies
- a sequence of `[key dep-type]` pairs (preserves build order —
useful when builds carry side effects like migrations)
- `nil` or `{}` for no dependencies
A key is a symbol (var), a keyword (abstract), or a string (env
var). A dep-type is `:required` or `:optional`:
- `:required` — the key must resolve to a non-nil object, otherwise
`di/start` fails with `::di/missing-dependency`.
- `:optional` — `build` receives `nil` for this key if it doesn't
resolve.
May be called multiple times per `di/start`. Should be pure.(description this)Returns a map describing the factory. Used by inspection and
logging. May be empty. See darkleaf.di.core for the conventional
keys.
Returns a map describing the factory. Used by inspection and logging. May be empty. See `darkleaf.di.core` for the conventional keys.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |