Liking cljdoc? Tell your friends :D

darkleaf.di.core


combine-dependenciesclj

(combine-dependencies)
(combine-dependencies a b)

Combines dependencies. Use it with reduce. Dependencies are a hash map of a key and a dependency type.

Combines dependencies. Use it with `reduce`.
Dependencies are a hash map of a key and a dependency type.
sourceraw docstring

Factorycljprotocol

buildclj

(build this dependencies)

Builds a stoppable object from dependencies.

Builds a stoppable object from dependencies.

dependenciesclj

(dependencies this)

Returns a map of a key and a dependency type. A type can be :required, :skipping-circular, or :optional.

Returns a map of a key and a dependency type.
A type can be :required, :skipping-circular, or :optional.
source

refclj

(ref key)
(ref key f & args)

Returns a factory referencing to another one.

(def port (di/ref "PORT" parse-long)

(def routes (di/template [["/posts" (di/ref `handler)]]))

(di/start root {:my-abstraction (di/refimplemntation)})

See template.

Returns a factory referencing to another one.

(def port (di/ref "PORT" parse-long)

(def routes (di/template [["/posts" (di/ref `handler)]]))

(di/start `root {:my-abstraction (di/ref `implemntation)})

See `template`.
sourceraw docstring

startclj

(start key & middlewares)

Starts a system of dependent objects.

The key argument is a name of the system root. Use symbols for var names, keywords for abstract dependencies, and strings for environments variables.

The key is looked up in a registry. By default registry uses system env and clojure namespaces to resolve string and symbol keys, respectively.

You can extend it with middlewares. Each middleware can be one of the following form:

  • a function registry -> key -> Factory
  • a vector of a function [registry args*] -> key -> Factory and it's arguments
  • a map of key and Factory instance
  • a sequence of the previous forms

Middlewares also allows you to instrument built objects. It's useful for logging, schema validation, AOP, etc. See with-decorator.

(di/start root {:my-abstraction implemntationsome-key replacement "LOG_LEVEL" "info"} (concat dev-middlwares test-middlewares) [di/with-decorator `log])

Returns a container contains started root of the system. The container implements AutoCloseable, Stoppable, IDeref and IFn.

Use with-open in tests to stop the system reliably.

See the tests for use cases.

Starts a system of dependent objects.

The key argument is a name of the system root.
Use symbols for var names, keywords for abstract dependencies,
and strings for environments variables.

The key is looked up in a registry.
By default registry uses system env and clojure namespaces
to resolve string and symbol keys, respectively.

You can extend it with middlewares.
Each middleware can be one of the following form:

- a function `registry -> key -> Factory`
- a vector of a function `[registry args*] -> key -> Factory` and it's arguments
- a map of key and `Factory` instance
- a sequence of the previous forms

Middlewares also allows you to instrument built objects.
It's useful for logging, schema validation, AOP, etc.
See `with-decorator`.

(di/start `root
          {:my-abstraction implemntation
           `some-key replacement
           "LOG_LEVEL" "info"}
          (concat dev-middlwares test-middlewares)
          [di/with-decorator `log])

Returns a container contains started root of the system.
The container implements `AutoCloseable`, `Stoppable`, `IDeref` and `IFn`.

Use `with-open` in tests to stop the system reliably.

See the tests for use cases.
sourceraw docstring

Stoppablecljprotocol

stopclj

(stop this)

Stops the object. Returns nothing.

Stops the object. Returns nothing.
source

templateclj

(template form)

Returns a factory for templating a data-structure. Replaces Factory instances with built objects.

(def routes (di/template [["/posts" (di/ref `handler)]]))

(def routes (di/template [["/posts" #'handler]]))

See ref.

Returns a factory for templating a data-structure.
Replaces `Factory` instances with built objects.

(def routes (di/template [["/posts" (di/ref `handler)]]))

(def routes (di/template [["/posts" #'handler]]))

See `ref`.
sourceraw docstring

with-decoratorclj

(with-decorator registry decorator-key & args)

Wraps registry to decorate or instrument built objects. Use it for logging, schema checking, AOP, etc. The decorator-key should refer to a var like the following one.

(defn my-instrumentation [{state :some/state} key object & args] (if (need-instrument? key object) (instrument state object args) object))

(di/start root [di/with-decoratormy-instrumentation arg1 arg2])

Wraps registry to decorate or instrument built objects.
Use it for logging, schema checking, AOP, etc.
The `decorator-key` should refer to a var like the following one.

(defn my-instrumentation [{state :some/state} key object & args]
  (if (need-instrument? key object)
    (instrument state object args)
    object))

(di/start `root [di/with-decorator `my-instrumentation arg1 arg2])
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close