0
0
NestJSframework~10 mins

Custom providers in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a custom provider token.

NestJS
const MY_SERVICE = '[1]';
Drag options to blanks, or click blank then click option'
AMyServiceToken
BmyService
CSERVICE
DCustomProvider
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic string like 'SERVICE' which may cause conflicts.
Using variable names instead of string tokens.
2fill in blank
medium

Complete the code to provide a custom class provider in NestJS.

NestJS
providers: [{ provide: MY_SERVICE, use[1]: MyServiceClass }]
Drag options to blanks, or click blank then click option'
Aclass
Bvalue
CClass
Dfactory
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'usevalue' or 'usevalue' instead of 'useClass'.
Confusing 'useFactory' with 'useClass'.
3fill in blank
hard

Fix the error in the custom provider definition by completing the blank.

NestJS
providers: [{ provide: MY_SERVICE, use[1]: () => new MyService() }]
Drag options to blanks, or click blank then click option'
AFactory
BFactoryFunction
CValue
DClass
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'useClass' with a function instead of a class.
Using 'useValue' with a function instead of a value.
4fill in blank
hard

Fill both blanks to create a custom provider that uses a value.

NestJS
providers: [{ provide: [1], use[2]: { name: 'Test' } }]
Drag options to blanks, or click blank then click option'
AMY_SERVICE
BValue
CuseClass
DMY_VALUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'useClass' when providing a value object.
Using an undefined token name.
5fill in blank
hard

Fill all three blanks to create a factory provider with dependencies.

NestJS
providers: [{ provide: [1], use[2]: (dep) => new MyService(dep), inject: [[3]] }]
Drag options to blanks, or click blank then click option'
AMY_SERVICE
BFactory
CDependencyService
DuseFactory
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'useClass' instead of 'useFactory' for factory providers.
Not listing dependencies in the inject array.
Using wrong token names.