Function: bindConstant()
ts
function bindConstant<T>(container: Container, entry: InjectableDescriptor): BindWhenOnFluentSyntax<T>;Defined in: src/wirestate-core/bind/bind-constant.ts:74
Binds a fixed value to a token.
Type Parameters
| Type Parameter | Description |
|---|---|
T | Value type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
container | Container | Container to bind into. |
entry | InjectableDescriptor | Descriptor with id and value. |
Returns
Inversify fluent syntax for additional constraints.
Remarks
Use constants for config, adapters, and test doubles. The same value comes back every time. No constructor runs.
Throws
WirestateError If entry.scopeBindingType is not Singleton.
Example
typescript
import { bindConstant, createContainer } from "@wirestate/core";
const API_URL = Symbol("API_URL");
const container = createContainer();
bindConstant(container, {
id: API_URL,
value: "https://api.example.com",
});
const apiUrl = container.get<string>(API_URL);