Angular Monorepo: How to resolve circular dependencies of two coupled modules (httpservice logs what is sent/sending all logs using httpservice)

Viewed 215

General information

  • Angular v10.x
  • NRWL 10.x
    • Monorepo containing multpile apps and libs

Situation

We're using multiple modules in our repository, The following two are troublesome:

  • CoreModule containing API logic (HttpRequestService). Capable of fail-over/retrying/selecting & storing the active gateway-URI)
  • LogModule containing everything about logs.

The new feature we need to implement is to send the collected logs to our backend. We would like to use our HttpRequestService.

But since the HttpRequestService writes logs and the LogService needs to use the HttpRequestService or at least the active gateway provided by the HttpRequestService, a circular dependency comes up.

So we've got the dependencies:

CoreModule  -> LogModule

LogModule   -> CoreModule

Options I see (but don't like)

  • Merge both to one module (Even the thought of it feels wrong.)
  • Outsourcing the active gateway-URI as BehaviorSubject into an additional (shared)module. This could be possible but error-prone and we'd end up having multiple sources sending HTTP requests instead of our generic service with retry mechanism and all (which leads to redundancy)
  • Putting another layer around the HTTP part and extracting that to an independent module which both existing modules can consume feels odd. I don't see a way to abstract it on a way where the logic would still be as readable and maintainable as now, plus if we need to resend the log messages, there we'd need information like how many tries, which gateway, etc.

Do you see another possibility? Lint throws "nx-enforce-module-boundaries".

Thanks a lot for your ideas in advance! :)

0 Answers
Related