@djodjonx/wiredi
    Preparing search index...

    Class TsyringeProvider

    tsyringe adapter implementing the ContainerProvider interface

    Provides integration between WireDI and tsyringe, allowing you to use tsyringe as your DI container while benefiting from WireDI's configuration and validation features.

    Implements

    Index

    Constructors

    Properties

    name: "tsyringe" = 'tsyringe'

    Provider name for debugging and logging purposes

    Methods

    • Registers a class in the container

      Type Parameters

      • T

        The type of the class instance

      Parameters

      • token: ProviderToken<T>

        Token (symbol or class) to register under

      • Optionalimplementation: Constructor<T>

        Class to instantiate (optional if token is a class)

      • lifecycle: ProviderLifecycle = ProviderLifecycle.Singleton

        Instance lifecycle (Singleton, Transient, or Scoped)

      Returns void

      // Register class as its own token
      provider.registerClass(UserService)

      // Register implementation for a symbol token
      provider.registerClass(TOKENS.Logger, ConsoleLogger, ProviderLifecycle.Singleton)
    • Registers a factory function in the container

      Type Parameters

      • T

        The type of the value produced by the factory

      Parameters

      • token: symbol

        Symbol token to register the factory under

      • factory: (provider: ContainerProvider) => T

        Function that creates the instance (receives the provider to resolve dependencies)

      Returns void

      provider.registerFactory(TOKENS.HttpClient, (p) => {
      return new HttpClient(p.resolve(TOKENS.ApiUrl))
      })
    • Registers a static value in the container

      Type Parameters

      • T

        The type of the value

      Parameters

      • token: symbol

        Symbol token to register the value under

      • value: T

        The value to register

      Returns void

      provider.registerValue(TOKENS.ApiUrl, 'https://api.example.com')
      
    • Resolves a dependency from the container

      Type Parameters

      • T

        The type of the resolved dependency

      Parameters

      Returns T

      Instance of the dependency

      Error if the token is not registered

      const logger = provider.resolve<LoggerInterface>(TOKENS.Logger)
      const userService = provider.resolve(UserService)