Bird
0
0

You want to create a singleton Logger service that is shared across all other services. How should you configure the dependency injection container?

hard📝 Conceptual Q8 of 15
LLD - Advanced LLD Concepts
You want to create a singleton Logger service that is shared across all other services. How should you configure the dependency injection container?
ARegister Logger as a singleton so all injections get the same instance
BRegister Logger as transient to create new instance each time
CDo not register Logger, create manually in each service
DRegister Logger with a factory that returns a new instance every call
Step-by-Step Solution
Solution:
  1. Step 1: Understand singleton service concept

    A singleton service means one shared instance used everywhere.
  2. Step 2: Choose correct registration type

    Registering Logger as singleton ensures all services get the same instance.
  3. Final Answer:

    Register Logger as a singleton so all injections get the same instance -> Option A
  4. Quick Check:

    Singleton registration = Shared instance [OK]
Quick Trick: Singleton services share one instance across app [OK]
Common Mistakes:
  • Registering singleton as transient
  • Creating manual instances instead of using container
  • Using factory that returns new instances each time

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes