How do you resolve Circular Dependencies in DI?

Updated Apr 28, 2026

Short answer

A circular dependency happens when Service A depends on Service B, which depends on Service A.

Deep explanation

This causes an infinite loop during resolution. The best solution is architectural: refactor the code to extract the shared logic into a new Service C. If refactoring is impossible, you can use Lazy Injection (delaying resolution until use) or Property/Setter injection to break the constructor loop.

Real-world example

An OrderService needs a NotificationService to send alerts, and the NotificationService needs the OrderService to lookup order details. Refactor to extract OrderLookupService.

Common mistakes

  • Ignoring the architectural flaw and using Service Locator hacks to bypass the loop.

Follow-up questions

  • What happens if a DI container detects a circular dependency without Lazy evaluation?

More Dependency Injection interview questions

View all →