ClassProvider

Interface defining a Class type provider.

See more...


interface ClassProvider<T = any> {
  provide: InjectionToken
  useClass: Type<T>
  scope?: Scope
  inject?: never
  durable?: boolean
}

See also

Description

For example:


const configServiceProvider = {
provide: ConfigService,
useClass:
  process.env.NODE_ENV === 'development'
    ? DevelopmentConfigService
    : ProductionConfigService,
};

Properties

Property Description
provide: InjectionToken

Injection token

useClass: Type<T>

Type (class name) of provider (instance to be injected).

scope?: Scope

Optional enum defining lifetime of the provider that is injected.

inject?: never

This option is only available on factory providers!

durable?: boolean

Flags provider as durable. This flag can be used in combination with custom context id factory strategy to construct lazy DI subtrees.

This flag can be used only in conjunction with scope = Scope.REQUEST.