1

I have UserService and GroupService in my app and it make sense that both services will know each other and use each other functions.

There are several tools in angular that give me to "fix" the circular dependency warning.

But everywhere it is written that if you have circular dependency, it's a sign that you have bad architecture.

So, what is the good architecture for cases like that? Why is it right to force (quite forcibly) one of the services not to know the other?

2 Answers 2

2

So the problem is when one service need to be instantiated, inside constructor it will require second service. But that second service in order to be instantiated, inside constructor it will require first service.

What you can do is move all the logic from these 2 services into one "parent" service, and use this "parent" service through the application.

Sign up to request clarification or add additional context in comments.

Comments

1

you have 2 options:

  1. Extract commonly needed parts of the logic into some SharedModule

  2. If some part of any modules logic is required in other modules then it doesn't belong into that feature module but in top level module (the one that starts the app, does core app things and loads other feature modules).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.