0

In developing an n-tier application, I seem to have hit a scenario where one service say service A needs to consume a method in service B. I do not want to duplicate logic but it does not seem like I should not have services calling one another either. What is the best way to handle this situation without violating any rules? I am thinking about taking the common method out of service B and add to another class and have both services inherit from this class.

user1790300
  • 2,143
  • 10
  • 54
  • 123

1 Answers1

1

Dependency Injection.

Service A expects a well defined service to be injected into it that is expressed with an interface. This way Service B can be injected as well as any other service implementing the same contract.

Wiktor Zychla
  • 47,367
  • 6
  • 74
  • 106