📝 Problem Description
Design an Inversion of Control (IoC) container and Dependency Injection (DI) framework. Support constructor injection, lifecycle management, and lazy/eager initialization.
👤 Use Cases
1.
Developer wants to registers service so that service available for injection
2.
Framework wants to resolves dependency so that injects instance into class
3.
Framework wants to manages lifecycle so that creates/destroys at right time
✅ Functional Requirements
- •Register services with interfaces
- •Constructor and property injection
- •Singleton and transient lifetimes
- •Circular dependency detection
- •Lazy initialization
- •Scoped containers (per request)
⚡ Non-Functional Requirements
- •Resolution time < 1ms
- •Low memory overhead
- •Thread-safe singleton creation
- •Clear error messages
⚠️ Constraints & Assumptions
- •Must handle circular dependencies
- •Reflection has performance cost
- •Scope management complexity
📊 Capacity Estimation
👥 Users
N/A (framework)
💾 Storage
O(N) for N registered services
⚡ QPS
100K+ resolutions/sec
📐 Assumptions
- • 1000 registered services
- • 10,000 resolutions per request
- • Most services are singletons
💡 Key Concepts
CRITICAL
Inversion of Control
Framework controls object creation, not application.
CRITICAL
Dependency Injection
Dependencies passed in, not created internally.
HIGH
Lifetime Scopes
Singleton (one), Transient (new each time), Scoped (per context).
HIGH
Dependency Graph
DAG of service dependencies for resolution order.
💡 Interview Tips
- 💡Start with the dependency injection pattern
- 💡Discuss the different lifetime scopes
- 💡Emphasize the circular dependency detection
- 💡Be prepared to discuss reflection vs code generation
- 💡Know the difference between constructor and property injection
- 💡Understand the service locator anti-pattern