Injection Not Working With Interfaces
See original GitHub issueHi!
What am I doing wrong here?
interface LoggingProvider {
error();
}
@Service()
class DefaultLoggingProvider implements LoggingProvider {
error() {
// .. logging goes here
}
}
@Service()
class UsersService {
constructor(private logger: LogginProvider) { }
}
log is undefined in UsersService unless I name it. Can TypeDI do interface injection without named services or am I missing something here?
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Dependency Injection not working When Interface is given as ...
Dependency Injection works on Constructor, Field and Interface level. Not at a method parameter level. Hope its clear.
Read more >Inject functions, not interfaces | Hackle's blog
Inject functions, not interfaces. We'll see how functions can replace interfaces in the case of dependency injection, leading to less and ...
Read more >DI: Injecting interfaces vs actual classes
One thing to understand, an interface is different than an interface (the keyword).
Read more >4 solutions for selective injection when the interface has ...
4 solutions for selective injection when the interface has multiple implementations · 1. Description of the problem · 2. Relatively low-level ...
Read more >How to register dependency injection for set of interfaces as a ...
Autofac has no problem with this, and why it recommends that, because it is going to generate a dynamic proxy anyway. Honestly you...
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

But why? What is the purpose of this, that we must provide specific class in the constructor?
constructor(private logger: LogginProvider)Isn’t it in conflict with whole idea behind DI pattern?
Hey @ldiego08!
As @Stradivario wrote, interfaces are compiled away and not part of the transformed code. You need to use classes. So you need to import the
DefaultLoggingProvider