registry
A small dependency-injection / wiring library for Scala 3.
A Registry is a list of functions and values. The Registry main function, make[T], can be called to make
a value of type T by invoking the first function that returns a T.
The function parameters are retrieved by recursively calling make on the Registry. That’s it!
import registry.*
case class Host(value: String)
case class Port(value: Int)
case class DbConfig(host: Host, port: Port)
case class App(db: DbConfig)
val r =
fun[App] +:
fun[DbConfig] +:
value(Host("localhost")) +:
value(Port(5432))
val app: App = r.make[App]
// app: App = App(DbConfig(host = Host("localhost"), port = Port(5432)))
Learn more:
-
Getting started install, first registry,
makevsmakeSafe. - Concepts how a
Registryactually works:- Registry and entries the four prepend operators and LIFO precedence.
- Resolution how
make[T]walks the dependency graph. - Safety what
+:andmakeSafe[T]check. - Memoization
sharevsconst, … - Customization refinements,
erase, …
- Modules per-artifact guides:
registrythe dependency-injection core.registry-catslift constructors, functions, and values into anyApplicative[F]registry-cborderive borerEncoder[T]/Decoder[T]instances for CBOR.registry-circederiveEncoder[T]/Decoder[T]instances from a registry.registry-scalacheckderiveGen[T]instances from a registry.