DI service not available in constructor
See original GitHub issueI need to initialize a websocket listener and want to do it in the constructor of the main AppController:
export class AppController {
@dependency websocketService!: WebsocketService;
constructor() {
this.websocketService.listen();
}
}
It seems like the service is not yet injected at the time I call it in the constructor. Is there a common approach on how to handle this with DI in FoalTS?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Dependency Injection in Service constructor not working?
Solved: In my JIRA plugin, I want to implement a service (which can be scheduled via the Services admin interface) which shall receive...
Read more >angular - Getting instance of service without constructor injection
If the constructor is in a component, it's the components injector, in a service it's the module injector (basically root injector if it's...
Read more >Dependency injection guidelines - .NET | Microsoft Learn
When designing services for dependency injection: Avoid stateful, static classes and ... Services not created by the service container.
Read more >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 >Dependency Injection and Controllers
By simply adding a service type to your controller as a constructor parameter, ASP.NET Core will attempt to resolve that type using its...
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 Free
Top 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
Ok, great! Thanks alot, this seems to work for now.
Even if a controller is not a service, you can also still retrieve it in the same way.
This approach would have the advantage of preparing your code to the new
init
feature.