Package Exports
- nestjs-extractor
- nestjs-extractor/.build/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nestjs-extractor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Description
NestJS module for extract providers from parent non-global modules
Installation
npm install --save nestjs-extractor
Usage
Create ZooConfigService and ZooConfigModule
@Injectable()
class ZooConfigService {
public get zooName(): string {
return process.env.ZOO_NAME ?? 'Central Park Zoo';
}
}
@Module({
providers: [ZooConfigService],
exports: [ZooConfigService],
})
class ZooConfigModule {}
Provide ZooConfigService through ExtractorModule in CatModule...
import { ExtractorModule } from 'nestjs-extractor';
@Module({
imports: [ExtractorModule.forFeature([ZooConfigService])],
providers: [CatService],
controllers: [CatController],
})
class CatModule {}
...and use ZooConfigService in CatController...
@Controller()
class CatController {
public constructor(
private readonly catService: CatService,
private readonly zooConfigService: ZooConfigService,
) {}
@Get('/cat/:catId/info')
public getCatInfo(
@Param('catId', ParseIntPipe) catId: number,
): string {
const catName = this.catService.getCatById(catId);
const zooName = this.zooConfigService.zooName;
return `Cat ${catName} from ${zooName}`;
}
}
Import CatModule in ZooModule
@Module({
imports: [CatModule, DogModule],
})
class ZooModule {}
Import ZooConfigModule and ZooModule in AppModule
@Module({
imports: [ZooConfigModule, ZooModule],
})
class AppModule {}
Options
You can provide the options for the providers search as the second argument of the ExtractorModule.forFeature()
function
type ExtractorModuleOptions = {
optional?: boolean;
};
optional
is needed for providers marked as@Optional()
@Injectable()
class Service {
public constructor(
@Inject(NestedService)
@Optional()
public readonly nestedService: NestedService | undefind,
) {}
}
@Module({
imports: [
ExtractorModule.forFeature([NestedService], { optional: true }),
],
providers: [Service],
})
class ServiceModule {}
License
MIT