Inject a provider in another provider, same module
See original GitHub issueI’m submitting a…
[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request
I have a service/provider, let’s say it’s call ServiceA1, in a module A marked as @Injectable(). In the same module i have another service/provider, let’s say it’s call ServiceA2, marked as @Injectable(). I want to inject ServiceA1 in ServiceA2 I try with:
@Injectable()
export class serviceA2 {
constructor( @Inject('ServiceA1') private readonly serviceA1: ServiceA1){
}
myFunction(integer A): {
const something = this.serviceA1.functionInServiceA1();
}
}
This code throw an error: serviceA1 undefined.
My module.ts
@Module({
imports: [],
controllers: [],
providers: [ServiceA1, ServiceA2]
})
I have to make another module to use serviceA2 in serviceA1?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Inject a provider in another provider, same module #1250
In the same module I have another service/provider, let's say it's call ServiceA2 , marked as @Injectable() . I want to inject ServiceA1...
Read more >Custom providers | NestJS - A progressive Node.js framework
The 'CONNECTION' custom provider uses a string-valued token. Let's see how to inject such a provider. To do so, we use the @Inject()...
Read more >Providing dependencies in modules - Angular
A provider is an instruction to the Dependency Injection system on how to obtain a value for a dependency. Most of the time,...
Read more >Inject Service From Another Module in NestJS (2022)
Let's create two modules (plus their controller and service) by NestJS CLI. The CLI creates these modules for you while adding them to...
Read more >Providers Within Modules - Configuration Language | Terraform
A module intended to be called by one or more other modules must not contain any provider blocks. A module containing its own...
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
Providers do not depend on each other, only serviceA2 depends(needs) on ServiceA1, so I think there are other solutions to using that forwardRef
@adrien2p I ended up splitting the module into two global modules. That effectively worked around the issue.