Skip to content

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 ParameterDescription
TValue type.

Parameters

ParameterTypeDescription
containerContainerContainer to bind into.
entryInjectableDescriptorDescriptor with id and value.

Returns

BindWhenOnFluentSyntax<T>

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);