Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pirumu/nest-qualifier
Dynamic provider for Nest JS
https://github.com/pirumu/nest-qualifier
Last synced: 29 days ago
JSON representation
Dynamic provider for Nest JS
- Host: GitHub
- URL: https://github.com/pirumu/nest-qualifier
- Owner: pirumu
- Created: 2022-09-26T04:00:36.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2022-09-26T04:04:32.000Z (about 2 years ago)
- Last Synced: 2024-04-29T07:45:03.247Z (8 months ago)
- Language: TypeScript
- Homepage:
- Size: 5.86 KB
- Stars: 14
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# Nest Qualifier
### How it works
Add alias metadata to the class and use it as token injection.### How to install
```shell
# npm
npm i --save @nattogo/nest-qualifier#yarn
yarn add @nattogo/nest-qualifier
```
### How to use
####
IRepository.ts
```ts
export interface IRepository {
findOne: (id: string) => Promise;
}
```MongoRepository.ts
```tsimport {Injectable} from "@nattogo/nest-qualifier";
@Injectable({
alias: 'MongoRepository'
})
export class MongoRepositoryImlp implements IRepository {
findOne(id: string): Promise<{ id: string }> {
return Promise.resolve({
id
});
}}
```MySQLRepository.ts
```tsimport {Injectable} from "@nattogo/nest-qualifier";
@Injectable({
alias: 'MySQLRepository'
})
export class MySQLRepositoryImpl implements IRepository {
findOne(id: string): Promise<{ id: string }> {
return Promise.resolve({
id
});
}}
```
ProductService.ts
```ts
import {Injectable} from "@nestjs/common";
import {Qualifier} from "@nattogo/nest-qualifier";@Injectable()
export class ProductService {
public constructor(
@Qualifier('MongoRepository') mongoRepository: IRepository,
@Qualifier('MySQLRepository') mysqlRepository: IRepository
) {}
}
```ProductModule.ts
```ts
import {Module} from "@nattogo/nest-qualifier";@Module({
providers: [
MongoRepository,
MySQLRepository,
],
})
export class ProductModule {
}
```### License
MIT License