Metatell AI Bot - v0.0.10
    Preparing search index...

    Class ServiceContainer

    Type-safe Service Container for Dependency Injection

    Features:

    • Full type safety with TypeScript - no string-based APIs
    • Automatic type inference using ServiceIdentifier tokens
    • Support for both interface tokens and concrete classes
    • Singleton and transient lifetime management
    • Compile-time type checking for all service registrations and retrievals
    Index

    Constructors

    Methods

    • Bind a class to itself (syntactic sugar)

      Type Parameters

      • T

      Parameters

      • implementation: new (...args: unknown[]) => T

        Class constructor

      • Optionaloptions: ServiceOptions

        Service options

      Returns this

    • Clear all singleton instances Useful for testing or resetting the container

      Returns void

    • Create a scoped container (child container) Useful for request-scoped services

      Returns ServiceContainer

    • Get a service from the container with automatic type inference

      Type Parameters

      • T

      Parameters

      • key: new (...args: any[]) => ServiceIdentifier<T>

        Service identifier (interface token or class) - strings are not supported

      Returns T

      Service instance with correct type inferred from the key

      Error if service is not registered

      const messageService = container.get(MessageService) // Type is inferred as IMessageService
      const appSettings = container.get(AppSettings) // Type is inferred as IAppSettings
    • Get a service from the container with automatic type inference

      Type Parameters

      • C extends new (...args: any[]) => any

      Parameters

      • key: C

        Service identifier (interface token or class) - strings are not supported

      Returns InstanceType<C>

      Service instance with correct type inferred from the key

      Error if service is not registered

      const messageService = container.get(MessageService) // Type is inferred as IMessageService
      const appSettings = container.get(AppSettings) // Type is inferred as IAppSettings
    • Check if a service is registered

      Type Parameters

      • T

      Parameters

      Returns boolean

      true if the service is registered

    • Register a service with the container using type-safe keys

      Type Parameters

      • T

      Parameters

      Returns this

      container.register(MessageService, () => new MessageServiceImpl())
      container.register(AppSettings, () => new AppSettingsImpl())
    • Register all services at once (bulk registration)

      Parameters

      Returns this