All files / src/internal/context service-initialization-context.mts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44                                                                                       
import type { InjectableScope } from '../../enums/index.mjs'
import type { IContainer } from '../../interfaces/container.interface.mjs'
import type { Injectors } from '../../utils/index.mjs'
 
/**
 * Context provided to injectors during service initialization.
 *
 * Extends FactoryContext with additional tracking information about
 * the service being initialized, its dependencies, and scope.
 * Used for scope upgrade tracking and dependency management.
 */
export interface ServiceInitializationContext {
  inject: Injectors['asyncInject']
  /**
   * The container instance for dependency resolution.
   * This may be either a Container or ScopedContainer.
   */
  container: IContainer
  addDestroyListener: (listener: () => void) => void
  getDestroyListeners: () => (() => void)[]
  /**
   * The name of the service being initialized.
   */
  serviceName: string
  /**
   * Set of dependency names that this service depends on.
   * Automatically populated as dependencies are resolved.
   */
  dependencies: Set<string>
  /**
   * The scope of the service being initialized.
   */
  scope: InjectableScope
  /**
   * Track a dependency that was resolved.
   * Used for scope upgrade tracking - if a Singleton service
   * resolves a Request dependency, the scope can be upgraded.
   *
   * @param name The name of the dependency
   * @param scope The scope of the dependency
   */
  trackDependency(name: string, scope: InjectableScope): void
}