Hierarchical injector
See original GitHub issueHi, in order to make more reusable code, I would like to create a module which use a component which is not a part of this module, nor include in an imported module. The component will be inject by the ApplicationModule (main module). It seems that this is not supported?
Example: AuthenticationModule has different controllers which use a UserService dependency. UserModule also has different controllers which use a UserService dependency.
Depending on application, the UserService may be implemented in different way. What I want is defining this in the ApplicationModule for all modules, once for all.
@Module({
modules: [ AuthenticationModule, UserModule ]
components: [
{ provide: UserService, useClass: MyCustomUserService }
]
})
class ApplicationModule {}
@Module({
controllers: [],
components: [ AuthenticationService ],
exports: [
AuthenticationService
]
})
class AuthenticationModule {}
export class AuthenticationService {
constructor(private userService: UserService) {}
}
I was expecting below code to work (similar to angular), but the userService dependency is not found.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Hierarchical injectors - Angular
With hierarchical dependency injection, you can isolate sections of the application and give them their own private dependencies not shared with the rest...
Read more >Hierarchical dependency injectors - Angular - w3resource
The Angular dependency injection system is hierarchical. There is a tree of injectors that parallels an app's component tree.
Read more >Understand Angulars Hierarchical Dependency Injection system
A hierarchical dependency injection system allows us to define different boundaries or scopes for our dependencies to run in and follows the ...
Read more >Angular Dependency Injection – Understanding hierarchical ...
Learn how to build custom form controls like select dropdown with multiselection in my new advanced Angular Forms course ...
Read more >Hierarchical injectors | Semantic portal — learn smart!
Injectors in Angular have rules that you can leverage to achieve the desired visibility of injectables in your apps. By understanding these rules, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @AurelieV, I made a set of improvements for a dependency injector, so now your example should works fine. Please, update your packages (since ~2.* version
@nestjs/core
,@nestjs/common
etc.) into latest versions.The problem is I do not want my two modules being dependant on each others. AuthenticationService can be use without UserModule. UserService is not part of UserModule