Coding task · NestJS course · Module 1: NestJS Basics

Factory Provider

Create a Factory Provider that dynamically creates instances.

Task

Define a storageProvider constant with provide: 'STORAGE_SERVICE', inject: [ConfigService] and a useFactory that receives ConfigService and returns new CloudStorageService() when config.get('STORAGE') === 'cloud', otherwise new LocalStorageService(). Write both classes yourself and add storageProvider to the providers of StorageModule.