Skip to content

Function: createContainer()

ts
function createContainer(options?: CreateContainerOptions): Container;

Defined in: src/wirestate-core/container/create-container.ts:109

Creates a Wirestate container.

Parameters

ParameterTypeDescription
optionsCreateContainerOptionsContainer setup.

Returns

Container

A new Wirestate-ready Container.

Remarks

This is an Inversify container with Wirestate pieces already installed:

  • Shared seed and targeted seed tokens.
  • Container-scoped EventBus, CommandBus, and QueryBus.
  • Transient WireScope, so each service gets its own scope handle.
  • Singleton default scope for normal services.

Child containers inherit parent bindings, but get their own buses and seeds. Think of a child container like a nested workbench: it can borrow parent tools, but it keeps its own inbox.

Throws

WirestateError If activate names a token missing from entries.

Example

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

@Injectable()
class LoggerService {}

@Injectable()
class CounterService {}

const container: Container = createContainer({
  entries: [CounterService, LoggerService],
  seeds: [[CounterService, { count: 10 }]],
  activate: [LoggerService],
});

const logger = container.get(LoggerService);