Skip to main content
zerotal

Documentation


Documentation / zerotal / index / ScopedResolver

Class: ScopedResolver

Defined in: packages/core/src/container/ScopedResolver.ts:13

Per-request cache of scoped bindings, flushed when the last reference is released.

Constructors

Constructor

new ScopedResolver(_container?): ScopedResolver

Defined in: packages/core/src/container/ScopedResolver.ts:19

Parameters

_container?

Container

Returns

ScopedResolver

Accessors

container

Get Signature

get container(): Container | undefined

Defined in: packages/core/src/container/ScopedResolver.ts:114

The root container — allows middleware to resolve non-scoped bindings.

Returns

Container | undefined

Methods

resolve()

resolve<T>(token, factory): Promise<T>

Defined in: packages/core/src/container/ScopedResolver.ts:27

Resolve a scoped binding, caching the instance for the rest of the request. Concurrent calls for the same token share a single in-flight promise.

Type Parameters

T

T

Parameters

token

unknown

factory

Factory<T>

Returns

Promise<T>

Throws

If the scope has already been flushed.


acquire()

acquire(): void

Defined in: packages/core/src/container/ScopedResolver.ts:60

Acquire a reference. Called synchronously by HttpContext.afterResponse() at registration time — before any await — so the request's finally block cannot flush the scope before the callback has a chance to run.

Returns

void


release()

release(): void

Defined in: packages/core/src/container/ScopedResolver.ts:74

Release a reference. When _refCount reaches 0, _doFlush() runs. Called by afterResponse() callback finally blocks and by flush().

Returns

void


flush()

flush(): void

Defined in: packages/core/src/container/ScopedResolver.ts:85

Called by Application.ts in the fetch handler's finally block. Releases the request's own reference (the initial 1). If afterResponse() callbacks are pending they hold their own references, so _doFlush() will not run until all of them have released.

Returns

void