Effect CommunityEC
Effect Community3y ago
15 replies
pula

Creating Tags for External Dependencies in Context

Hi, quite new to Effects and enjoying it so far. Just wondering if there is a standard pattern for creating Tags for external dependencies in context.

I have the following service where DynamoDBClient and UserStoreConfig are dependencies. Right now I'm creating Tags in a shared lib for all non-service dependencies, but seems a bit boilerplaty . Just wondering if there is a cleaner way to define tags and inject these?

example:
interface UserService {
  getUser(id: string): Effect.Effect<never, Error, User>
}

const UserStore = Context.Tag(UserService)

const DDBUserStore = Layer.effect(
  Effect.gen(function* (_) {
    const config = yield* _(UserStoreConfig)
    const ddbClient = yield* _(DynamoDBClient)

    return UserStore.of({
      getUser: () => {
        ...
      }
    })
  })
)
Was this page helpful?