codejump

Custom Providers

Preview — 3 of 10 questions

What does the useValue provider syntax accomplish?

AIt instantiates a class lazily
BIt creates a new instance per request
CIt runs a factory function on every injection
DIt registers an existing value/object/constant under a token so it can be injected directly

How can you make the token LoggerService resolve to FileLogger in production but ConsoleLogger elsewhere?

ARegister { provide: LoggerService, useClass: isProd ? FileLogger : ConsoleLogger }
BUse two @Injectable() decorators
CSubclass both at runtime
DIt is impossible to swap implementations

When using useFactory, how do you supply dependencies to the factory function?

AImport them as globals inside the factory
BFactories cannot have dependencies
CList their tokens in the inject array; Nest resolves them and passes them as factory arguments in order
DUse @Inject() inside the factory body

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.