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 Parameter | Default type | Description |
|---|---|---|
T extends object | object | Bound object type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
container | Container | Container to bind into. |
entry | | InjectableDescriptor<unknown, unknown> | Newable<T> | Service class or descriptor. |
options | BindEntryOptions | Binding options for class entries. |
Returns
void
Remarks
bindEntry is the router behind createContainer({ entries }).
It chooses the right binding helper:
- Class constructor: singleton service via bindService.
ConstantValue: fixed value via bindConstant.DynamicValue: factory value via bindDynamicValue.Instance: service class behind a custom token.
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",
});