Unique scope identifier (auto-generated for child scopes).
Optionalparent: SynapseContextParent context for hierarchical resolution.
ReadonlyscopeUnique scope identifier (auto-generated for child scopes).
Get all registered tokens across this scope and all parents.
Whether this context has been disposed.
The active memory guard, if enabled.
The ref registry for this context, if any refs have been acquired.
Returns undefined if acquireRef() has never been called.
Number of services registered in this scope.
Get all registered tokens (this scope only, not parent).
Acquire a tracked, ref-counted reference to a service.
Returns a ServiceRef that must be .release()'d when no
longer needed. Multiple acquireRef() calls for the same singleton
token return different refs to the same instance — the ref count
tracks how many holders exist.
The service token to resolve.
A new ServiceRef<T> linked to this context's ref registry.
// Component A
const rpcRef = ctx.acquireRef(Tokens.RPC);
await rpcRef.current.getBalance(pubkey);
// Component B — same singleton, separate ref
const rpcRef2 = ctx.acquireRef(Tokens.RPC);
ctx.refCount(Tokens.RPC); // → 2
// Cleanup
rpcRef.release(); // ref count → 1
rpcRef2.release(); // ref count → 0
Acquire tracked refs for multiple tokens at once.
Returns a ServiceBinding whose .services proxy lazily
resolves each token. A single .release() frees all refs.
Record mapping property names to service tokens.
A binding with lazy services and batch release.
Create a child scope that inherits all parent registrations.
Scoped services get fresh instances in the child scope. The child scope is tracked and disposed when the parent is disposed.
OptionalscopeId: stringUnique identifier for the child scope.
A new SynapseContext linked to this parent.
Dispose this context and all child scopes.
Calls .dispose() on all singleton/scoped services that implement
Disposable. After disposal, any call to resolve() throws.
Number of services disposed.
Enable a memory guard with configurable thresholds.
The guard monitors ref counts and emits pressure/leak events. Can only be called once per context.
Optionalconfig: MemoryGuardConfigGuard thresholds.
The created MemoryGuard.
Check if a token has a provider (searches parent scopes too).
Unsubscribe from a container event.
Subscribe to a container event.
Number of active (unreleased) refs for a specific token.
Returns 0 if no refs have been acquired or the ref registry
hasn't been initialized yet.
Register a service provider for a token.
The service token.
How to create the service.
Optionaltags: string[]Optional tags for filtering.
this for chaining.
Register a service only if the token is not already registered.
Useful for default/fallback providers that should not override user-provided registrations.
Optionaltags: string[]Register multiple services at once.
Array of { token, provider, tags? } descriptors.
this for chaining.
Resolve a service synchronously.
Resolve a service asynchronously.
Required for services registered with useAsyncFactory.
Also works for sync providers (wraps result in a resolved promise).
Return a snapshot of registered services for debugging.
Try to resolve a service; return undefined if not registered.
Add a resolve middleware.
Middleware functions wrap every resolve() call. They execute in
the order they are added (first-in, outermost).
Middleware function.
this for chaining.
The main IoC service container.
Provides type-safe dependency injection with support for:
DisposableSince
1.2.0