Stratal API Reference
    Preparing search index...

    Function Transient

    • Mark a class as injectable

      This decorator wraps tsyringe's @injectable decorator and optionally associates a token with the class. The actual lifecycle (Singleton, Request, Transient) is determined at registration time, not decoration time.

      Lifecycle Control:

      • Use scope: Scope.Singleton in module providers for singleton
      • Use scope: Scope.Request in module providers for request-scoped
      • Default is Transient (new instance per resolution)

      Type Parameters

      • T

      Parameters

      Returns <TFunction extends new (...args: never[]) => unknown>(
          target: TFunction,
      ) => TFunction

      @Transient()
      export class UserService {
      constructor(@inject(DI_TOKENS.Database) private db: DatabaseService) {}
      }

      // In module:
      @Module({
      providers: [UserService] // Transient by default
      })
      @Transient(DI_TOKENS.ConnectionManager)
      export class ConnectionManager implements Disposable {
      // ...
      }

      // In Application.ts:
      container.register(DI_TOKENS.ConnectionManager, ConnectionManager, Scope.Request)
      @Transient()
      export class ConsumerRegistry {
      // ...
      }

      // In module:
      @Module({
      providers: [
      { provide: DI_TOKENS.ConsumerRegistry, useClass: ConsumerRegistry, scope: Scope.Singleton }
      ]
      })