# Fx.provideServiceEffect

Acquires one service with an Effect before running the Fx.

## Signatures

```ts
export declare const provideServiceEffect: {
    <Id, S, E2, R2>(tag: Context.Service<Id, S>, serviceEffect: Effect.Effect<S, E2, R2>): <A, E, R>(fx: Fx<A, E, R>) => Fx<A, E | E2, Exclude<R, Id> | R2>;
    <A, E, R, Id, S, E2, R2>(fx: Fx<A, E, R>, tag: Context.Service<Id, S>, serviceEffect: Effect.Effect<S, E2, R2>): Fx<A, E | E2, Exclude<R, Id> | R2>;
};
```

## Why

Some service instances require effectful configuration but do not warrant a
separately named Layer. This keeps acquisition failure and dependencies
explicit in the returned Fx type.

## Ownership and lifetime

The service Effect runs once per subscription while {@link provide} builds
its Layer. A failure prevents the source from starting. On success, the
service is available for the whole source run and its identifier is removed
from `R`; acquisition errors and every requirement in `R2` are added. In
particular, an `Effect.acquireRelease` service Effect still leaves
`Scope.Scope` in the returned Fx requirements—the private Layer Scope does
not erase that public requirement. The caller must provide that Scope.

## Examples

```ts
import { Context, Effect } from "effect"
import { provideServiceEffect } from "@typed/fx/Fx"
import { fromEffect } from "@typed/fx/Fx"

class Config extends Context.Service<Config, { readonly url: string }>()("Config") {}
const request = fromEffect(Effect.map(Config, (x) => x.url))
const runnable = provideServiceEffect(request, Config, Effect.succeed({ url: "/api" }))
```

Scoped acquisition keeps `Scope` in the returned Fx requirements
```ts
import { Context, Effect } from "effect"
import { provideServiceEffect } from "@typed/fx/Fx"
import { fromEffect } from "@typed/fx/Fx"
import { collectAll } from "@typed/fx/Fx"

class Config extends Context.Service<Config, { readonly url: string }>()("Config") {}
const request = fromEffect(Effect.map(Config, (x) => x.url))
const acquired = Effect.acquireRelease(
Effect.succeed({ url: "/api" }),
() => Effect.void
)
const scopedFx = provideServiceEffect(request, Config, acquired)
const program = Effect.scoped(collectAll(scopedFx))
```
