Currently, I have two services in my application. ServiceA is non-singleton and provided to components through the Providers array, while ServiceB is a singleton that is listed in its module's Providers array. Both services work perfectly fine independently.
The challenge I am facing now is that I need to access ServiceA from within ServiceB, but I'm unsure of how to achieve this. It seems like injecting a non-singleton service into a singleton service is not straightforward.
Most recommendations suggest putting the service in the bootstrap or module declaration, but this is not feasible for me since ServiceA must maintain its non-singleton behavior while ServiceB remains a singleton.
// Module setup
... providers: [ServiceB]
// Non-singleton
@Injectable()
export class ServiceA
// Singleton
@Injectable()
export class ServiceB {
constructor(ServiceA) // <-- Having trouble accessing ServiceA here
I attempted using something like constructor(Inject(ServiceA) serviceA), but encountered the same errors.
Error: DI Error No provider for ServiceA!
- Is there a way to effectively "provide" a non-singleton service to a singleton service, both marked as @Injectable?