zio.blocks.scope.Wire
See theWire companion object
A recipe for constructing a service and its dependencies.
Wires are the building blocks of dependency injection in Scope. They describe how to construct a service given access to its dependencies via a context.
==Wire Types==
- Wire.Shared: Converted to a reference-counted Resource.shared (default)
- Wire.Unique: Converted to a fresh Resource.unique each time
==Creating Wires==
Use Wire.shared[T] and Wire.unique[T] macros for automatic derivation from constructors, or create wires manually for custom construction logic.
==Usage Example==
// Define a service with its wire
class Database(config: Config)
object Database {
val wire: Wire[Config, Database] = Wire.shared[Database]
}
// Create a unique wire for request-scoped services
class RequestHandler(db: Database)
object RequestHandler {
val wire: Wire[Database, RequestHandler] = Wire.unique[RequestHandler]
}
// Create a Resource from wires
val appResource = Resource.from[App](
Wire(Config("localhost", 8080)),
Wire.shared[Database]
)
Type parameters
- In
-
the dependencies required (contravariant - accepts supertypes)
- Out
-
the service(s) produced (covariant - produces subtypes)
Attributes
- Companion
- object
- Source
- Wire.scala
- Graph
-
- Supertypes
- Known subtypes
Members list
In this article