Dependency Injection - consider alternative for resolving TypeScript interfaces
See original GitHub issueRelevant Package
This feature request is for @angular/core
Description
DI can’t handle TypeScript interfaces
Describe the solution you’d like
I noticed Aurelia has an interesting solution using Symbol
s for unique injection tokens to allow slick resolving of interfaces.
Described here
Describe alternatives you’ve considered
the current workaround is to use TypeScript abstract classes.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Top 5 TypeScript dependency injection containers
In this article, we'll review five containerized dependency injection tools for writing dependency injection systems in TypeScript.
Read more >Dependency Injection & Inversion Explained | Node.js w
Dependency Injection and Depedency Inversion are two related but commonly misused terms in software development. In this article, we explore ...
Read more >Setting Up Dependency Injection with TypeScript in an ...
At the end of this post, you will learn what dependency injection is useful for, how to set it up in your TypeScript...
Read more >Dependency Injection and Inversion of Control in JavaScript
We will consider its implementation using the Dependency Injection design ... As JS does not support interfaces we will consider the TypeScript example....
Read more >Aurelia DI with typescript interfaces
As Mike said, Aurelia doesn't support this dependency resolving feature yet. ... (since interface is reserved in TypeScript I called it @i).
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
Thanks @nzacca. Yes, I looked briefly at InjectionToken and I presume it would be an ingredient in the solution?
My point is it feels like Aurelia’s approach fairly cleanly hides the details from the application programmer and it would be nice if Angular could provide a similar (or better!) API.
I like how they have done rather minimal boilerplate and it allows a traditional IFoo -> Foo type registration, as shown at the end of the section linked above.
As far as I can tell, Angular’s answer to this erased-interface problem is abstract classes. I’m hoping they will consider this technique and/or improve upon it to give us a more natural feeling interface-to-concrete DI experience.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.