1.0.5 • Published 6 months ago

nest-discovery v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

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

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

7 months ago

1.0.2

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago