I’m guessing, it is a common question, but I will try to describe my current issue.
I have a base service, lets name it ‘CoreService’, that provides I would say “main” functionality: handle data in DB (we have a centralized DB in our applications). There are a number of other applications, some of them have their own DB for local purposes. And there is one simple ‘NotificationService’. Its purpose is to broadcast messages to different subscribers.
Usually, this NotificationService is called from ‘ExternalWorld’ and sends notifications to different services (among them is ‘CoreService’).
Today I saw a necessity to call ‘NotificationService’ from ‘CoreService’.
My concern here is that I am introducing a circular dependency: NotificationService needs to know how to send messages to each service (including ‘CoreService’ so it needs to know about the ‘CoreService’ interface and as a result it needs to reference ‘CoreService’) and ‘CoreService’ needs to send messages to ‘NotificationService (so it needs to reference it too)… Circular dependency…
Question: How should we build our architecture to handle such issue?
Thanks a lot!
When I completed writing question I found some idea:
Inside of ‘NotificationService’ I need to define 2 interfaces ‘IMessagesSender’ and ‘IMessagesReceiver’.
In this case we won’t remove circular dependency, but it seems like a solution…
Right now, it is hard for me to say what is the best way ans what are pros and cons of this solution, so please comment it (and/or suggest the better one).
Thanks a lot!