# Class DIContainer

Dependency Injection Container Cyclomatic complexity: 5

- Defined in di/container.ts:43

##### Index

### Constructors

constructor

### Properties

services

### Methods

clear
has
register
resolve

## Constructors

### constructor

- new DIContainer(): DIContainer

  #### Returns DIContainer

## Properties

### `Private` `Readonly` services

services: Map<symbol, ServiceDescriptor<unknown>> = ...

- Defined in di/container.ts:44

## Methods

### clear

- clear(): void

  Clear all registered services and cached instances.

  Useful for testing and cleanup between test suites.

  #### Returns void

  #### Example

      afterEach(() => {
        container.clear();
      });

  #### Since

  0.8.0

  - Defined in di/container.ts:137

### has

- has(token: symbol): boolean

  Check if a service is registered Cyclomatic complexity: 1

  #### Parameters

  - token: symbol

    Service identifier token

  #### Returns boolean

  `true` if the token is registered, `false` otherwise

  #### Since

  0.8.0

  - Defined in di/container.ts:119

### register

- register<T>(
  token: symbol,
  factory: ServiceFactory<T>,
  lifetime?: ServiceLifetime,
  ): void

  Register a service with the container Cyclomatic complexity: 1

  #### Type Parameters

  - T

  #### Parameters

  - token: symbol

    Service identifier token

  - factory: ServiceFactory<T>

    Factory function to create service instances

  - lifetime: ServiceLifetime = 'singleton'

    Service lifetime ('singleton' or 'transient')

  #### Returns void

  #### Example

      const ReportServiceToken = Symbol('ReportService');
      container.register(
        ReportServiceToken,
        (c) => new ReportService(c.resolve(EPClientToken)),
        'singleton'
      );

  #### Since

  0.8.0

  - Defined in di/container.ts:66

### resolve

- resolve<T>(token: symbol): T

  Resolve a service from the container Cyclomatic complexity: 4

  #### Type Parameters

  - T

  #### Parameters

  - token: symbol

    Service identifier token

  #### Returns T

  Resolved service instance

  #### Throws

  If service is not registered

  #### Example

      const reportService = container.resolve(ReportServiceToken);

  #### Since

  0.8.0

  - Defined in di/container.ts:90