0

I'm building a service layer that going to keep a business application. There'are too difficult to avoid circular dependency. In my application, I have two modules which include A and B.

In module A, I have a function called "formatDataModuleA". In module B, I have a function called "formatDataModuleB".

The problem is I wanna use the function "formatDataModuleB" in A and otherwise with module B. So, it will cause a circular dependency problem. I can not use a sharing or common module to contain these functions. So, there'are any light-weight for reusing the business logic with service layer pattern and avoid circular dependency?

stevenH
  • 155
  • 3
  • 13
  • 2
    Why can't you use a common module? That's the solution staring you in the face. – Michael Beeson Apr 22 '20 at 10:54
  • 2
    If your module is CommonJS (uses `require()`, not `import`) then Node [can handle circular dependencies](https://nodejs.org/api/modules.html#modules_cycles) although it is messy and often undesirable. – RickN Apr 22 '20 at 11:00
  • Because one business belongs to a specific service and should be kept by this module. – stevenH Apr 22 '20 at 11:01
  • @RikkusRukkus. Thank you. But I can not use this module if I import. It always returns empty object. – stevenH Apr 22 '20 at 11:04

0 Answers0