Composable dependency injection and resource lifecycle management inspired by Effect-ts and ZIO.
Layers model recipes for acquiring and releasing environmental context and services.
Layers can be composed horizontally with merge>, vertically with compose>,
and provided to effect pipelines with provide-layer> or managed with start-layer!
and launch-sync!.
Composable dependency injection and resource lifecycle management inspired by Effect-ts and ZIO. Layers model recipes for acquiring and releasing environmental context and services. Layers can be composed horizontally with `merge>`, vertically with `compose>`, and provided to effect pipelines with `provide-layer>` or managed with `start-layer!` and `launch-sync!`.
(->LayerSystem context scope)Constructs a LayerSystem instance.
Constructs a `LayerSystem` instance.
(compose>)(compose> layer)(compose> l1 l2)(compose> l1 l2 & more)Composes layers vertically. Each layer in the sequence is provided with the accumulated context of all previous layers. Resources are released in reverse acquisition order.
Composes layers vertically. Each layer in the sequence is provided with the accumulated context of all previous layers. Resources are released in reverse acquisition order.
(from-effect> key effect)Creates a layer providing {key val} by evaluating effect without release lifecycle.
Creates a layer providing `{key val}` by evaluating `effect` without release lifecycle.
(from-value> key val)Creates a layer providing {key val} with no lifecycle management.
Creates a layer providing `{key val}` with no lifecycle management.
(from-values> context-map)Creates a layer providing context-map with no lifecycle management.
Creates a layer providing `context-map` with no lifecycle management.
Protocol for composable dependency injection and lifecycle management layers.
Protocol for composable dependency injection and lifecycle management layers.
(-build-eff this scope)Returns an IEffect that builds the layer within scope and yields the context map.
Returns an `IEffect` that builds the layer within `scope` and yields the context map.
Protocol for managing resource finalizers within a lifecycle scope.
Protocol for managing resource finalizers within a lifecycle scope.
(add-finalizer! this finalizer-eff)Registers a finalizer effect into the scope.
Registers a finalizer effect into the scope.
(close-scope!> this)Returns an effect that deterministically executes all registered finalizers in reverse order of registration.
Returns an effect that deterministically executes all registered finalizers in reverse order of registration.
(launch-sync! layer)(launch-sync! layer opts)Starts a layer synchronously, registers a JVM shutdown hook to clean up on process termination,
and optionally blocks if :join? true in opts.
Starts a layer synchronously, registers a JVM shutdown hook to clean up on process termination, and optionally blocks if `:join? true` in `opts`.
(layer? x)Returns true if x implements ILayer.
Returns true if `x` implements `ILayer`.
(make-map> acquire-eff release-fn)Creates a lifecycle-managed layer providing a map of services.
acquire-eff is an Effect returning a context map.
release-fn is a pure function (fn [context-map] -> Effect) returning an Effect to release the resources.
Creates a lifecycle-managed layer providing a map of services. `acquire-eff` is an `Effect` returning a context map. `release-fn` is a pure function `(fn [context-map] -> Effect)` returning an `Effect` to release the resources.
(make-scope)Creates a fresh, empty IScope instance.
Creates a fresh, empty `IScope` instance.
(make> key acquire-eff release-fn)Creates a lifecycle-managed layer for a single service key.
acquire-eff is an Effect returning the resource.
release-fn is a pure function (fn [resource] -> Effect) returning an Effect to release the resource.
Creates a lifecycle-managed layer for a single service `key`. `acquire-eff` is an `Effect` returning the resource. `release-fn` is a pure function `(fn [resource] -> Effect)` returning an `Effect` to release the resource.
(merge>)(merge> layer)(merge> l1 l2)(merge> l1 l2 & more)Merges multiple layers horizontally. Layers are evaluated independently and their resulting context maps are merged. Resources are released in reverse acquisition order.
Merges multiple layers horizontally. Layers are evaluated independently and their resulting context maps are merged. Resources are released in reverse acquisition order.
(provide-layer> layer)(provide-layer> effect layer)Executes effect within the context provided by layer, deterministically
releasing all acquired layer resources upon completion.
Supports standalone and thread-first pipeline usage: (-> (fx/service> :http/server) (fx-layer/provide-layer> app-layer))
(fx-layer/provide-layer> (fx/service> :http/server) app-layer)
Executes `effect` within the context provided by `layer`, deterministically
releasing all acquired layer resources upon completion.
Supports standalone and thread-first pipeline usage:
(-> (fx/service> :http/server)
(fx-layer/provide-layer> app-layer))
(fx-layer/provide-layer> (fx/service> :http/server) app-layer)(start-layer! layer)(start-layer! layer initial-context)Starts a layer synchronously, returning an active LayerSystem record containing
the initialized :context and implementing java.io.Closeable.
Starts a layer synchronously, returning an active `LayerSystem` record containing the initialized `:context` and implementing `java.io.Closeable`.
(stop-layer! system)Stops an active system, deterministically executing all layer finalizers in reverse order.
Stops an active system, deterministically executing all layer finalizers in reverse order.
(with-layer> layer use-eff-fn)Executes use-eff-fn (a function (fn [context] -> Effect)) within the context of layer,
guaranteeing complete teardown of all acquired layer resources upon completion.
Executes `use-eff-fn` (a function `(fn [context] -> Effect)`) within the context of `layer`, guaranteeing complete teardown of all acquired layer resources upon completion.
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 |