Skip to main content

port

@rotorsoft/act-root


@rotorsoft/act-root / act/src / port

Function: port()

port<Port>(injector): (adapter?) => Port

Defined in: libs/act/src/ports.ts:77

Creates a singleton port with optional adapter injection.

The first call initializes the adapter (using the provided adapter or the injector's default). Subsequent calls return the cached singleton. Adapters are disposed in reverse registration order during disposeAndExit.

Type Parameters

Port

Port extends Disposable

Parameters

injector

Injector<Port>

Named function that creates the default adapter

Returns

Port function: call with no args to get the singleton, or pass an adapter on the first call to override the default

(adapter?) => Port

Example

const store = port(function store(adapter?: Store) {
return adapter || new InMemoryStore();
});
const s = store(); // InMemoryStore