Wire

zio.blocks.scope.Wire
See theWire companion trait
object Wire

Companion object providing wire factory methods and wire classes.

Attributes

Companion
trait
Source
Wire.scala
Graph
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Wire.type

Members list

Type members

Classlikes

final case class Shared[-In, +Out](makeFn: (Scope, Context[In]) => Out) extends Wire[In, Out]

A wire that produces a reference-counted shared instance via Resource.shared.

A wire that produces a reference-counted shared instance via Resource.shared.

The underlying instance may be shared across multiple allocating scopes. A reference count tracks usage, and the instance is released when the last referencing scope is closed. This is the default wire type produced by shared[T].

Type parameters

In

the dependencies required to construct the service

Out

the service type produced

Value parameters

makeFn

the function that constructs the service given a finalizer and context

Attributes

Companion
object
Source
Wire.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait Wire[In, Out]
class Object
trait Matchable
class Any
Show all
object Shared

Companion object for Wire.Shared providing factory methods.

Companion object for Wire.Shared providing factory methods.

Attributes

Companion
class
Source
Wire.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Shared.type
final case class Unique[-In, +Out](makeFn: (Scope, Context[In]) => Out) extends Wire[In, Out]

A wire that produces a fresh instance each time it's used.

A wire that produces a fresh instance each time it's used.

Unlike shared wires, unique wires create new instances for each dependent service. Use for services that should not be shared, like request-scoped resources or per-call state.

Type parameters

In

the dependencies required to construct the service

Out

the service type produced

Value parameters

makeFn

the function that constructs the service given a finalizer and context

Attributes

Companion
object
Source
Wire.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait Wire[In, Out]
class Object
trait Matchable
class Any
Show all
object Unique

Companion object for Wire.Unique providing factory methods.

Companion object for Wire.Unique providing factory methods.

Attributes

Companion
class
Source
Wire.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Unique.type

Inherited and Abstract types

type MirroredElemLabels <: Tuple

The names of the product elements.

The names of the product elements.

Attributes

Inherited from:
Mirror
Source
Mirror.scala
type MirroredLabel <: String

The name of the type.

The name of the type.

Attributes

Inherited from:
Mirror
Source
Mirror.scala

Value members

Concrete methods

def apply[T](t: T): Shared[Any, T]

Creates a wire that injects a pre-existing value.

Creates a wire that injects a pre-existing value.

The value is wrapped in a shared wire with no dependencies. If the value is AutoCloseable, close() is registered automatically when the wire is used.

Type parameters

T

the service type

Value parameters

t

the value to inject

Attributes

Returns

a shared wire that provides the value

Source
Wire.scala

Inherited methods

transparent inline def shared[T]: Shared[_, T]

Derives a shared Wire for type T by inspecting its constructor.

Derives a shared Wire for type T by inspecting its constructor.

The macro inspects T's primary constructor and generates a wire that:

  • Retrieves constructor parameters from the context
  • Passes a Scope parameter if present
  • Registers close() as a finalizer if T extends AutoCloseable

When converted to a Resource via toResource, shared wires produce a reference-counted Resource.shared so dependents receive the same instance.

Type parameters

T

the service type to construct (must be a class, not a trait or abstract)

Attributes

Returns

a shared wire for constructing T

Inherited from:
WireCompanionVersionSpecific (hidden)
Source
WireVersionSpecific.scala
transparent inline def unique[T]: Unique[_, T]

Derives a unique Wire for type T by inspecting its constructor.

Derives a unique Wire for type T by inspecting its constructor.

Like shared[T], but the wire creates a fresh instance each time it's used. Use for services that should not be shared across dependents.

Type parameters

T

the service type to construct (must be a class, not a trait or abstract)

Attributes

Returns

a unique wire for constructing T

Inherited from:
WireCompanionVersionSpecific (hidden)
Source
WireVersionSpecific.scala