Clarification on Using Effect.Service and Dependencies in Effect Typescript

Hey, playing around with the DI system right now and just wanted to make sure I understand stuff correctly.
Currently I am trying to integrate better-auth and drizzle. I have the following code now:
// db.ts
import * as PgDrizzle from '@effect/sql-drizzle/Pg'
import { PgClient } from '@effect/sql-pg'
import { Effect, Redacted } from 'effect'
import { Resource } from 'sst'
import * as schema from './schema'

export class PgDatabase extends Effect.Service<PgDatabase>()(
  '@app/PgDatabase',
  {
    dependencies: [
      PgClient.layer({
        username: Resource.GastradexPostgres.username,
        password: Redacted.make(Resource.GastradexPostgres.password),
        database: Resource.GastradexPostgres.database,
        host: Resource.GastradexPostgres.host,
        port: Resource.GastradexPostgres.port,
      }),
    ],
    effect: PgDrizzle.make({
      schema,
      casing: 'snake_case',
    }),
  }
) {}


My questions is if I used Effect.Service correctly here? The dependencies part seems to most confusing. If I understand correctly its a sort of default implementation of the dependencies the Service uses correct? Not sure if it would have been better if I used Layer.provide(PgClient.layer({...})) at the entry of my programm instead where I also provide the PgDatabase. Or if I should have defined a static layerWithClient method in the PgDatabase class, that does the some thing
Idk just so many patterns and I am unsure of the the tradeoffs/differences 😅
Was this page helpful?