Skip to content

LazyInject

@tsed/di

Usage

typescript
import { LazyInject } from "@tsed/di";

See /packages/di/src/types/common/decorators/lazyInject.ts.

Overview

ts
function LazyInject(resolver: () => Promise<{
    default: unknown;
}>): PropertyDecorator;
export function LazyInject(key: string, resolver: () => Promise<{
    default: unknown;
}>): PropertyDecorator;

Description

Lazy load a provider from his package and invoke only when the provider is used

typescript
import type {PlatformException} from "@tsed/platform-exceptions";

@Injectable()
export class MyService {
  @LazyInject(() => import("@tsed/platform-exceptions"))
  exceptions: Promise<PlatformException>;
}

default

ts
default: unknown;

default

ts
default: unknown;

Released under the MIT License.