0

as the title implies, I'm trying to create a master service to provide my services to a component. I'm really not sure what to search for when it comes to this problem. I've seen somethings about putting a service in another service but they don't try to use that service in more than one component. These basic beginner things we're able to be seen with a simple search.

Some of the services need to communicate with each other and they work fine until one has a dependency on another, which depends on that last one and it causes a circular dependency. But all I want is for them to communicate, and not really "depend" on each other if that makes since. When I have the master service include everything it needs and i put it in two or more components I get one or both of the following errors:

1) Cannot call on "service" before it's initialized.
2) Warning: Circular Dependency

If it's only in one component however, it works how I want Eg. Master.Auth.methodHere()

I've tried putting the master service in the providers, it has the root injector it's just not putting it all together to easily call what I need.

Solution Thanks to AnuShankars response, I was set on the right track. I found this
Inject a service manually

And it really put me to the end. Thanks Anu

n0774k3n
  • 1
  • 1

1 Answers1

0

Can use Injector for this. Inject it via constructor as usual, and then when you will need some service that leads to the circular dependency, get that service from it. for example

const example = this.injector.get(ExampleService);