Spot problems with circular dependency

Solution 1:

The clean way to handle this is using dependency injection, to keep the dependencies at the interface level.

It's ok for UserMain to depend on FilesInternaService and it's ok for FileMain to depend on UserInternalService; but it's not ok for UserMain to depend on FileMain or for FileMain to depend on UserMain. In other words, it's not ok to depend on concrete implementation.

An instance of FilesInternaService should be injected into UserMain and an instance of UserInternalService should be injected into FileMain.


References

  1. Are circular dependencies considered bad design?
  2. Why are circular references considered harmful?
  3. https://softwareengineering.stackexchange.com/questions/11856/whats-wrong-with-circular-references
  4. https://softwareengineering.stackexchange.com/questions/306483/how-to-solve-circular-dependency