Skip to content

Function: bindEntry()

ts
function bindEntry<T>(
   container: Container, 
   entry: 
  | InjectableDescriptor<unknown, unknown>
  | Newable<T>, 
   options?: BindEntryOptions): void;

Defined in: src/wirestate-core/bind/bind-entry.ts:107

Binds a class or descriptor into a container.

Type Parameters

Type ParameterDefault typeDescription
T extends objectobjectBound object type.

Parameters

ParameterTypeDescription
containerContainerContainer to bind into.
entry| InjectableDescriptor<unknown, unknown> | Newable<T>Service class or descriptor.
optionsBindEntryOptionsBinding options for class entries.

Returns

void

Remarks

bindEntry is the router behind createContainer({ entries }).

It chooses the right binding helper:

Throws

WirestateError If the descriptor is invalid.

Example

typescript
import { BindingType, Injectable, bindEntry, createContainer } from "@wirestate/core";

const API_URL = Symbol("API_URL");

@Injectable()
class UserService {}

const container = createContainer();

bindEntry(container, UserService);
bindEntry(container, {
  id: API_URL,
  bindingType: BindingType.ConstantValue,
  value: "https://api.example.com",
});