question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dependency Injection - consider alternative for resolving TypeScript interfaces

See original GitHub issue

Relevant 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 Symbols 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:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ShawnTalbertcommented, Mar 31, 2020

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.

0reactions
angular-automatic-lock-bot[bot]commented, May 1, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found