Instantiating a service with specific initialization values while preserving dependencies can be ...

Trying to wrap my head around layers and services, how can I instantiate this service with certain init values, as you would pass some init into a constructor, while still preserving the dependencies?

export class FontSubStyleMemory extends Effect.Service<FontSubStyleMemory>()(
  "FontSubStyleMemory",
  {
    effect: Effect.gen(function* (size: number /* <---- cant do this ???? */) {
      const { toCanvasPx } = yield* CanvasService;
      return yield* Effect.succeed({
        size: toCanvasPx(size)
        /* ... */
      });
    }),
    dependencies: [CanvasService.Live],
  },
) {}


Also, is it possible to specify layer dependencies in the Context version of service creation, like this one?

export class CanvasService extends Context.Tag("CanvasService")<
  CanvasService,
  {
    toCanvasPx: (value: number) => number;
  }
>() {
  static Live = Layer.service(this);
}
Was this page helpful?