Factory and Alias Providers — Fundamentals · NestJS

Build a provider from configuration with useFactory and inject, and give one instance a second token with useExisting.

What you will learn

Read the theory for Factory and Alias Providers

All Fundamentals lessons

All NestJS courses

loading types…

What you'll learn

  • Provide a class Nest cannot construct through useFactory, with other providers handed in through inject
  • Alias one instance under a second token with useExisting, and know why useClass there would be a second instance
  • Choose an implementation at startup with a useClass expression, and mark an injected token optional