API Reference

KeyedInstanceFactory

Abstract base class in @rs-x/core for id-based singleton instance reuse with built-in reference counting.

Type: abstract class KeyedInstanceFactory<...>

Description

Ensures one instance per id and tracks how many owners currently use that instance.

When the reference count reaches zero, the instance is removed and teardown hooks run.

Parameters

TIdgeneric type parameter

Identifier key used to reuse one instance per id.

TDatageneric type parameter

Input data required to create or resolve an instance.

TInstancegeneric type parameter

Managed runtime instance type.

Return type

create(data) returns { referenceCount, instance, id }.

release(id) returns { referenceCount, instance | null }.

Usage notes

create(data) increments ref count and returns existing or newly created instance.

release(id) decrements ref count and triggers cleanup when it reaches zero.