Skip to content

Services and the edge

A service is an interface for domain dependencies, emitted as a Context.Service class (§16 shows both sides). Users! yields the live implementation. Wiring implementations uses standard library code without dedicated syntax: layers are written with Layer. Layer is the one Effect namespace Hem does not auto-import (the other namespaces in this tour are inferred from usage); import it explicitly with import { Layer } from "effect":

let UsersLive = Layer.effect(Users, effect {
  let db = Db!
  makeUsersService(db)
})

And the edge of a Workers app is one pipe chain in a route module:

export let loader = ({ params }: Route.LoaderArgs) =>
  getUser(params.userId) |> Effect.provide(AppLayer) |> Effect.runPromise

If a required service is omitted, the compiler reports which services are missing and where they were introduced, rather than emitting TypeScript’s Type 'Users' is not assignable to type 'never'.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close