From 4ecc373a3bcd7ad2867a9f18a6b4ff020c428ecd Mon Sep 17 00:00:00 2001 From: Kamil Mysliwiec Date: Wed, 5 Jun 2019 12:07:21 +0200 Subject: [PATCH] Update dependency-injection.md --- content/fundamentals/dependency-injection.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/content/fundamentals/dependency-injection.md b/content/fundamentals/dependency-injection.md index 62ecba172a..e245c941a6 100644 --- a/content/fundamentals/dependency-injection.md +++ b/content/fundamentals/dependency-injection.md @@ -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