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 989295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:46:11+00:00 2026-05-16T05:46:11+00:00

Possible Duplicate: What is dependency injection? I’ve read the Wikipedia page. I’ve read an

  • 0

Possible Duplicate:
What is dependency injection?

I’ve read the Wikipedia page.
I’ve read an articulate explanation from a book from Apress.

I still don’t understand what it is, or why it’s useful.

StackOverflow seems to be the best place to ask this. 🙂 Can an expert give me an easy to understand explanation?

  • 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-16T05:46:12+00:00Added an answer on May 16, 2026 at 5:46 am

    Dependency Injection means, in a nutshell, that you don’t create the objects you need and you program against interfaces. By this, a class is easier to be tested, is much more independent of other code.

    two examples:

    First example:

    using Core.Service.X;
    using Core.Service.Y;
    
    public class A //without injection
    {
      private ServiceX servicex;
      private ServiceY servicey;
    
      public A ()
      {
        servicex = new ServiceX();
        servicey = new ServiceY();
      }
    }
    

    In this example, class A has to be aware of ServiceX and ServiceY and their implementation (this is a very simple example, ServiceX and ServiceY could have complex constructors themselves.

    Second example:

    using Core.ServiceInterfaces;
    
    public class B //without injection
    {
      private IServiceX servicex;
      private IServiceY servicey;
    
      public A (IServiceX serx, IServiceY, sery)
      {
        servicex = serx;
        servicey = sery;
      }
    }
    

    In this example, the class isn’t aware of the specific implementation of either of the classes, it doesn’t construct them itself. By this, the class is way more reuseable, as another party (normaly a DI-Container like Castle Windsor, Unity or MEF) takes care of the construction of these.

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

Sidebar

Related Questions

Possible Duplicate: What is dependency injection? Spring is the framework from where the concept
Possible Duplicate: R suppress startupMessages from dependency I've read about using sink(NUL) / sink(/dev/null)
Possible Duplicate: Inversion of Control < Dependency Injection Could anyone please help me to
Possible Duplicate: What is dependency injection? Other developers on my team keep talking about
Possible Duplicate: Help with Dependency Injection in .NET Hi friends, It is a couple
Possible Duplicate: What is dependency injection? Spring uses dependency injection pattern. Can someone show
Possible Duplicate: Setting up a build dependency without using a reference? Is it possible
Possible Duplicates: What is dependency injection? What exactly is Spring for? I want to
Possible Duplicate: What is the fastest XML parser in PHP? I still need to
Possible Duplicates: Difference between Dependency Injection (DI) & Inversion of Control (IOC) Inversion of

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.