Bird
Raised Fist0

How can you resolve circular dependencies between two services, ServiceA and ServiceB, using a dependency injection framework?

hard๐Ÿง  Conceptual Q9 of Q15
LLD - Advanced LLD Concepts
How can you resolve circular dependencies between two services, ServiceA and ServiceB, using a dependency injection framework?
ARegister both services as singletons without dependencies
BUse lazy injection or provider functions to defer dependency resolution
CRemove one service to break the cycle
DInject dependencies manually outside the container
Step-by-Step Solution
Solution:
  1. Step 1: Understand circular dependency problem

    ServiceA depends on ServiceB and vice versa, causing infinite loop if injected directly.
  2. Step 2: Use lazy injection or providers

    Lazy injection defers creation until needed, breaking the cycle safely.
  3. Final Answer:

    Use lazy injection or provider functions to defer dependency resolution -> Option B
  4. Quick Check:

    Circular dependency fix = Lazy injection [OK]
Quick Trick: Lazy injection breaks circular dependency loops [OK]
Common Mistakes:
MISTAKES
  • Ignoring circular dependencies causing runtime errors
  • Trying to remove services instead of fixing injection
  • Injecting dependencies manually defeats container benefits

Want More Practice?

15+ quiz questions ยท All difficulty levels ยท Free

Free Signup - Practice All Questions
More LLD Quizzes