Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 740123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:28:45+00:00 2026-05-14T08:28:45+00:00

How do we identify when to use dependency injection or singleton pattern. I have

  • 0

How do we identify when to use dependency injection or singleton pattern.
I have read in lot of websites where they say “Use Dependency injection over singleton pattern”. But I am not sure if I totally agree with them. For my small or medium scale projects I definitely see the use of singleton pattern straightforward.

For example Logger. I could use Logger.GetInstance().Log(...)
But, instead of this, why do I need to inject every class I create, with the logger’s instance?.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:28:45+00:00Added an answer on May 14, 2026 at 8:28 am

    If you want to verify what gets logged in a test, you need dependency injection. Furthermore, a logger is rarely a singleton – generally you have a logger per each of your class.

    Watch this presentation on Object-oriented design for testability and you’ll see why singletons are bad.

    The problem with singletons is that they represent a global state which is hard to predict, especially in tests.

    Have in mind that an object can be de-facto singleton but still be obtained via dependency-injection, rather than via Singleton.getInstance().

    I’m just listing some important points made by Misko Hevery in his presentation. After watching it you will gain full perspective on why it is better to have an object define what its dependencies are, but not define a way how to create them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have some objective C code which I use to identify the difference
I have read that one could use the class dump command line tool to
I can use GetHashCode() to identify an object but is there any way to
I have read many posts on Session-scoped data in MVC, but I am still
Was just reading about different algos disassemblers use to identify binary as assembly instructions.
What's the best heuristic I can use to identify whether a chunk of X
How do you use GAP to identify the name of a group from its
When I use a dynamic segment in the Ember.Router then will ember automatically identify
I'm doing a project that use image processing techniques to identify different objects and
I'm trying to use Integrated Windows Authentication combined with a DirectorySearcher to identify and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.