Decorators

@system-inc/base-foundation · 515c140 · 13 symbols

Class decorator factory that will cause the dependency container to return the same instance each time a resolution for this dependency is requested. This is similar to being a singleton, however if a child container is made, that child container will resolve an instance unique to it.

Accepts an optional BaseModuleKey declaring module membership — see Injectable.

ContainerScoped(moduleKey?: BaseModuleKey<unknown>): (target: T) => void

View source ↗

@Inject

decorator

Parameter decorator factory that allows for interface information to be stored in the constructor's metadata.

Accepts a TypedInjectionKey<T> in addition to the standard tsyringe InjectionToken<T> shapes; the typed key carries the resolved type for static verification by the base/inject-type-matches-parameter lint rule.

Inject(token: BaseInjectionToken<T>): TypedParameterDecorator<T>

View source ↗

@Injectable

decorator

Class decorator factory that allows the class' dependencies to be injected at runtime.

Uses the default registration scope: Transient. A new instance will be created with each resolve

Pass a BaseModuleKey to declare the class a member of that module. Membership drives module-aware database resolution: token-less @InjectRepository/@InjectDatabase parameters in the class resolve to the database the module resolves to in the running worker (the module's orm.databaseName, as overridden by the worker's database registration modifier). All the injectable-family decorators (@Singleton, @WorkerScoped, @ContainerScoped, @ResolutionScoped) accept the same optional key.

Injectable(moduleKey?: BaseModuleKey<unknown>): (constructor: T) => void

View source ↗

@InjectAll

decorator

Parameter decorator factory that resolves all registrations for the given token as an array.

Accepts TypedInjectionKey<T> and any TypedBinding subclass in addition to the standard tsyringe token shapes.

InjectAll(token: BaseInjectionToken<T>): TypedParameterDecorator<T[]>

View source ↗

Inject an array of optional dependencies.

InjectAllOptional(token: BaseInjectionToken<T>, options?: ProviderOptions): TypedParameterDecorator<T[]>

View source ↗

Parameter decorator factory that resolves all registrations through a transform.

InjectAllWithTransform(token: BaseInjectionToken<T>, transformer: Constructor<{ transform: (...args: any[]) => unknown }>, ...args: unknown[]): ParameterDecorator
  • token

    The token of the object to be resolved.

  • transformer

    The transform class.

  • args

    Arguments passed to the transform method.

View source ↗

@InjectLazy

decorator

Inject a lazy dependency.

InjectLazy(token: BaseInjectionToken<T>, options?: ProviderOptions): TypedParameterDecorator<LazyInstance<T>>

View source ↗

Inject an optional dependency.

InjectOptional(token: BaseInjectionToken<T>, options?: ProviderOptions): TypedParameterDecorator<T | undefined>

View source ↗

Parameter decorator factory that resolves a token through a transform before injection.

InjectWithTransform(token: BaseInjectionToken<T>, transformer: Constructor<{ transform: (...args: any[]) => unknown }>, ...args: unknown[]): ParameterDecorator
  • token

    The token of the object to be resolved.

  • transformer

    The transform class.

  • args

    Arguments passed to the transform method.

View source ↗

@Provider

decorator

Registers the decorated method as a provider for the specified token.

When the token is resolved, the method will be called and the result will be returned.

Provider(token: BaseInjectionToken<T>, options?: ProviderOptions): TypedMethodDecorator<T | ObjectFactory<T> | undefined>

View source ↗

Class decorator factory that will cause the dependency container to use the same instance to be resolved for each resolution of this dependency during a single resolution chain.

Accepts an optional BaseModuleKey declaring module membership — see Injectable.

ResolutionScoped(moduleKey?: BaseModuleKey<unknown>): (target: T) => void

View source ↗

@Singleton

decorator

Class decorator factory that registers the class as a singleton within the global container.

Each resolve will return the same instance (including resolves from child containers), from the global scope.

Accepts an optional BaseModuleKey declaring module membership — see Injectable.

You probably want to use @ContainerScoped or @WorkerScoped() instead.

Singleton(moduleKey?: BaseModuleKey<unknown>): (constructor: T) => void

View source ↗

@WorkerScoped

decorator

Class decorator factory that registers the class with the @worker scoped container.

Each resolve will return the same instance (including resolves from child containers), from the @worker scope.

Accepts an optional BaseModuleKey declaring module membership — see Injectable.

Very similar to @Singleton, but scoped to the worker instead of globally.

WorkerScoped(moduleKey?: BaseModuleKey<unknown>): (constructor: T) => void

View source ↗