Skip to content

Commit

Permalink
Update dependency-injection.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec authored Jun 5, 2019
1 parent ba34f92 commit 4ecc373
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions content/fundamentals/dependency-injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,26 @@ export class ApplicationModule {}

> info **Hint** If your factory needs other providers, you have to pass their tokens inside the `inject` array. Nest will pass instances as arguments of the function in the same order.
### Use existing
#### Use existing

The `useExisting` is way of aliased existed providers. For example, the token `newLoggerService` is a alias for `LoggerService`.
The `useExisting` allows you creating aliases for existing providers. For example, the token `AliasedLoggerService` is an alias for `LoggerService`.

```typescript
@Injectable()
class LoggerService {}
const loggerServiceProvider = {
provide: LoggerService,
useClass: LoggerService
};
const newLoggerServiceProvider = {
provide: 'newLoggerService',

const loggerAliasProvider = {
provide: 'AliasedLoggerService',
useExisting: LoggerService
};

@Module({
providers: [loggerServiceProvider, newLoggerServiceProvider],
providers: [LoggerService, loggerAliasProvider],
})
export class ApplicationModule {}
```

> info **Hint** The instance of `LoggerService` which via provider `newLoggerService` token is equals to the instance which via provider `LoggerService` token.
> info **Hint** The instance of `LoggerService` will be equal to the instance defined by `AliasedLoggerService` token.
#### Export custom provider

Expand Down

0 comments on commit 4ecc373

Please sign in to comment.