Bird
0
0

Identify the error in the following dependency injection registration code:

medium📝 Analysis Q6 of 15
LLD - Advanced LLD Concepts
Identify the error in the following dependency injection registration code:
container.register('Database', DatabaseClass);
container.register('UserRepo', UserRepositoryClass, ['Db']);
ADependency name 'Db' does not match registered service 'Database'
BUserRepositoryClass should not have dependencies
CDatabaseClass is not registered correctly
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check dependency names in registration

    UserRepo depends on 'Db' but only 'Database' is registered, so names mismatch.
  2. Step 2: Identify cause of error

    The container cannot resolve 'Db' because it was never registered under that name.
  3. Final Answer:

    Dependency name 'Db' does not match registered service 'Database' -> Option A
  4. Quick Check:

    Dependency name mismatch = Error [OK]
Quick Trick: Dependency names must match registered service names exactly [OK]
Common Mistakes:
  • Assuming partial name match works
  • Ignoring dependency list correctness
  • Thinking registration order fixes name mismatch

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes