Class: InjectionToken<T>
Defined in: src/wirestate-core/binding/binding-tokens.ts:36
Typed reference token for dependencies stored in a container.
Remarks
Use an InjectionToken<T> when a dependency needs a named, collision-free runtime key that carries the resolved TypeScript type. It works well for configuration, external objects, interfaces, and service contracts that should be resolved through an explicit key. The token is identified by object reference, not by its description.
Example
import { Container, InjectionToken, Injectable, inject } from "@wirestate/core";
interface RuntimeConfig {
readonly apiUrl: string;
}
const RUNTIME_CONFIG = new InjectionToken<RuntimeConfig>("RUNTIME_CONFIG");
const container = new Container({
bindings: [{ token: RUNTIME_CONFIG, value: { apiUrl: "https://api.example.com" } }],
});
@Injectable()
class ApiClient {
public constructor(private readonly config = inject(RUNTIME_CONFIG)) {}
}Type Parameters
| Type Parameter |
|---|
T |
Constructors
Constructor
new InjectionToken<T>(description: string | symbol): InjectionToken<T>;Defined in: src/wirestate-core/binding/binding-tokens.ts:48
Creates an injection token with a human-readable description.
Parameters
| Parameter | Type | Description |
|---|---|---|
description | string | symbol | Description used in diagnostics. |
Returns
InjectionToken<T>
Methods
toString()
toString(): string;Defined in: src/wirestate-core/binding/binding-tokens.ts:55
Returns a diagnostic label for this token.
Returns
string
Human-readable token label.
Properties
_type?
protected readonly optional _type?: T;Defined in: src/wirestate-core/binding/binding-tokens.ts:41
Phantom field that ties the token to its value type. It exists so InjectionToken<A> is not assignable to InjectionToken<B>.