Combining Services in a Runtime Without Repeated Dependencies

Thus far I have been explicitly providing dependencies to effects whenever necessary, but I'm researching the use of runtimes to bundle services into a single container. I'd like to know whether there is a way to build the runtime in such a way that all services/layers are merged together without the need to repeatedly provide the same dependency as seen with providing A to B and C:
class A extends Effect.Service<A>()("A", {
  succeed: { doTheThing: () => Effect.succeed(true) }
}) {}

class B extends Effect.Service<B>()("B", {
  effect: Effect.gen(function*() {
    const a = yield* A
    return {}
  })
}) {}

class C extends Effect.Service<C>()("C", {
  effect: Effect.gen(function*() {
    const a = yield* A
    return {}
  })
}) {}

const MainLayerLive = Layer.mergeAll(
  A.Default,
  // Goal: Simplify this duplication.
  B.Default.pipe(Layer.provide(A.Default)),
  C.Default.pipe(Layer.provide(A.Default))
)
const ServerRuntime = ManagedRuntime.make(MainLayerLive)
Was this page helpful?