#Not sure what is the best practice for two modules relying on each other's providers

3 messages · Page 1 of 1 (latest)

spring snow
#

I have a module that has providers for consuming and publishing messages to a rabbitmq queue, let's call it ModuleA.
In addition, I have another module that has a provider that updates and reads from a DB, let's call it ModuleB.
When a message is consumed from rabbitmq, a DB action needs to happen with the help of a relevant provider from ModuleB..
Similarly, when a specific controller endpoint (the controller is in moduleB) is called, a message needs to be published to the rabbitmq queue with the help of a relevant provider from ModuleA.
So, here's my options:

  1. Make use of forwardRef so that each module imports the other one.
  2. Use the same providers for both modules (which don't rely on each other in and of themselves)
  3. Something else? Third module maybe somehow?

I would like to know what might be the best practice for this kind of situation and if options 1 and 2 are even good options at all

tiny cape
#
  1. Create a third module that contains whatever shared code both of the other modules need.
  2. If the modules are that much related, maybe consider making them into just one
  3. Use events to communicate across modules without calling them directly.
spring snow
#

And which of all these 5 options seems to be the best in my situation in your opinion?