nest-discovery
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Features

  • Provide a way to discover providers with decorator
  • Provide easy to use options by default

Installation

$ npm i --save nest-discovery

Usage

In order to use it you need first to enableShutdownHooks, then import the module

imports: [
  DiscoverableModule,
  ...
]

then annotate classes with

@Discoverable('key')
export class XStrategy implements Strategy {}
---
@Discoverable('key')
export class YStrategy implements Strategy {}

After that create a service which will discover all annotated services:

@Injectable()
export class StrategiesService implements OnModuleInit {
  private strategies: Strategy[] = [];

  constructor(private readonly discoverableService: DiscoverableService) {}

  onModuleInit() {
    this.strategies = this.discoverableService.getProviders<Strategy[]>('key');
  }
}

Now we can use strategies property

Package Sidebar

Install

npm i nest-discovery

Weekly Downloads

37

Version

1.0.5

License

ISC

Unpacked Size

25.6 kB

Total Files

11

Last publish

Collaborators

  • widmo