Skip to content

Function: getBindingToken() ​

ts
function getBindingToken(binding: Binding): ServiceToken;

Defined in: src/wirestate-core/binding/binding-tokens.ts:103

Returns the token a binding resolves under.

Parameters ​

ParameterTypeDescription
bindingBindingService class or descriptor to inspect.

Returns ​

ServiceToken

Token used for container resolution.

Remarks ​

A bare service class is its own token, and a descriptor carries an explicit one. Use it when working with the Binding union, such as the entries of ContainerConfig.bindings, instead of narrowing the union at each call site.

Example ​

typescript
import { getBindingToken, Injectable, InjectionToken } from "@wirestate/core";

@Injectable()
class LoggerService {}

const API_URL = new InjectionToken<string>("API_URL");

getBindingToken(LoggerService); // LoggerService
getBindingToken({ token: API_URL, value: "https://api.example.com" }); // API_URL