rootContext
The stable root asimo container that serves as the default context for all root stores.
Signature
const rootContext: Container<any>;Description
rootContext is a stable proxy object (named "asm") that wraps an internal container. When services are added via registerRootService, the internal container is rebuilt, but the rootContext reference stays the same. This means child containers created with extends: [rootContext] automatically see newly registered services.
Usage
Default store context
All root stores created with createStore use rootContext as their default IoC context:
const store = createStore(Counter);// The store uses rootContext (or a descendant) as its IoC contextExtending for tests
Create child containers for test isolation:
import { createContainer } from "@asimojs/asimo";import { rootContext } from "@asimojs/mom";
const testContext = createContainer({ name: "test", extends: [rootContext], services: [fakeTimeController.factory],});
const store = createStore(CountDown, { context: testContext });Fetching services directly
import { rootContext } from "@asimojs/mom";
const timeService = await rootContext.fetch(TimeServiceIID);Behavior
- Named
"asm"internally (stable root) - Rebuilt whenever
registerRootServiceis called - Child containers extending it inherit all registered services
- Default context for root stores unless overridden via the
contextparam - The proxy ensures method calls are always forwarded to the current internal container
Notes
- Do not modify
rootContextdirectly — useregisterRootServiceto add services - For test-specific overrides, always use
createContainer({ extends: [rootContext] })rather than modifying the root