class DiContainer
implements IContainer
Since 0.1.0

Dependency injection container implementing IContainer.

Resolution order for a token:

  1. Provider registry — explicit DI registrations (class, factory, value).
  2. External resolver — when autoRegister is enabled and the token exists in the external source (ServiceRegistry), the instance is fetched and cached as a singleton for subsequent lookups.
  3. Throw — if neither source has the token.

Circular dependencies are detected via an instance-level resolution stack that persists across recursive resolve() calls (including factory providers that call back into the container).

Constructors

DiContainer(config: ContainerConfig)
Parameters

Container configuration

Methods

createScope(): IContainer

Creates a child scope. Scoped services resolve to one instance per scope; singletons are shared with the parent.

has(token: string): boolean

Reports whether a token is registered.

register<T>(
token: string,
provider: Provider<T>,
options?: ProviderOptions
): void

Registers a provider under a token.

resolve<T>(token: string): T

Resolves an instance, constructing it (and its dependencies) as needed.

Usage

import { DiContainer } from "di-plugin/src/index.ts";