# Service

Defines an Effect context service that is simultaneously a `Subject`, `Fx`, and `Sink` facade.

## Signatures

```ts
export declare function Service<Self, A, E = never>(): <const Id extends string>(id: Id) => Subject.Class<Self, Id, A, E>;
```

## Why

A named subject often represents an application-wide event boundary. `Service` keeps that
boundary type-safe and lets producers, consumers, and layers compose through Effect's normal
service channel instead of a module-global mutable instance.

## Ownership and lifetime

Defining the class acquires nothing. Calling its static `make` creates a layer backed by scoped
`Subject.make`; releasing the layer interrupts subscriptions and clears replay. Static `Fx` and
`Sink` operations require `Self`, then delegate to the installed subject. Invalid replay
capacities fail layer construction with `Cause.IllegalArgumentError`.

## Examples

```ts
import { Effect } from "effect"
import { Fx } from "@typed/fx"
import * as Subject from "@typed/fx/Subject"

class Notifications extends Subject.Service<Notifications, string>()("Notifications") {}

const program = Effect.gen(function* () {
  yield* Notifications.onSuccess("saved")
  return yield* Fx.first(Notifications)
}).pipe(Effect.provide(Notifications.make(1)), Effect.scoped)
```
