Effect CommunityEC
Effect Community•3y ago•
340 replies
hipnotic3141

Issue with Layers and Dependency

I'm having an issue with Layers. I'm providing the dependency to a Layer but the resulting Layer still has that dependency as R
interface ServiceA {
    get: () => string;
}

interface ServiceB {
    get: () => string;
}

const ServiceA = Context.Tag<ServiceA>();
const ServiceB = Context.Tag<ServiceB>();

const ServiceALive = Layer.succeed(ServiceA, ServiceA.of({ get: () => 'A' }));
const ServiceBLive = Layer.effect(
    ServiceB,
    Effect.gen(function* (_) {
        const a = yield* _(ServiceA);
        return ServiceB.of({ get: () => a.get() + 'B' });
    })
);

// Layer.Layer<ServiceA, never, ServiceA>
const mainLayer = ServiceBLive.pipe(Layer.provide(ServiceALive));
//        ^------ Still requires ServiceA
Was this page helpful?