Bird
Raised Fist0

If a required dependency is not registered in the container, what is the most likely runtime behavior when the client requests the service?

medium🧠🧾 Concept Trace Q4 of Q15
OOP & Design Patterns - Interface Segregation & Dependency Inversion - Fat Interfaces & IoC
Consider a system using Dependency Injection (DI) with an IoC container. If a required dependency is not registered in the container, what is the most likely runtime behavior when the client requests the service?
AThe IoC container throws a runtime exception indicating a missing dependency.
BThe client silently receives a null reference for the dependency.
CThe IoC container automatically creates a default implementation of the dependency.
DThe client falls back to a cached instance of the dependency.
Step-by-Step Solution
Solution:
  1. Step 1: Understand DI container behavior

    Most IoC containers throw runtime exceptions when a required dependency is missing to alert the developer.
  2. Step 2: Analyze options

    The IoC container throws a runtime exception indicating a missing dependency correctly describes the typical exception thrown. The client silently receives a null reference for the dependency is incorrect; silent null injection leads to hidden bugs. The IoC container automatically creates a default implementation of the dependency is false; containers do not create default implementations automatically. The client falls back to a cached instance of the dependency is incorrect; fallback caching is not standard behavior.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Missing dependency -> runtime exception from IoC container [OK]
Quick Trick: Missing DI registration causes runtime exception [OK]
Common Mistakes:
MISTAKES
  • Assuming null is injected silently
  • Believing IoC auto-creates defaults
  • Thinking fallback caching is automatic
Trap Explanation:
PITFALL
  • Candidates often think missing dependencies fail silently or are auto-created, missing the explicit error signaling.
Interviewer Note:
CONTEXT
  • Tests understanding of DI container error handling at runtime.
Master "Interface Segregation & Dependency Inversion - Fat Interfaces & IoC" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes