Conditionally Providing Layers in an Application

is there a way to conditionally provide layers to my application? I have a layer that takes care of environment variables and i want to use that information to pick another layer based on the data from the other layer, is that possible?

something like

const ProductionEmailProviderServiceLayer; // Layer<EmailProviderService, never, EnvService>

const DevEmailProviderServiceLayer; // Layer<EmailProviderService, never, EnvService>

const EmailProviderServiceLayer = Layer.effect(
  EmailProviderService,
  Effect.gen(function* (_) {
    const env = yield* _(EnvService);

    if (env.ENVIRONMENT === "development") {
      return yield* _(DevEmailProviderServiceLayer);
    }

    return yield* _(ProductionEmailProviderServiceLayer);
  }),
);
Was this page helpful?