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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:47:33+00:00 2026-05-29T11:47:33+00:00

Possible Duplicate: Inversion of Control < Dependency Injection Could anyone please help me to

  • 0

Possible Duplicate:
Inversion of Control < Dependency Injection

Could anyone please help me to understand DI and IOC with simple C# example please? As I understand IOC is the inversion of control flow (which means nothing to me) and DI means injecting interfaces via properties or constructors. Not sure how these two are related.

Thank you.

  • 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-29T11:47:34+00:00Added an answer on May 29, 2026 at 11:47 am

    I’ll add an explanation that I’ve been told is a helpful one.

    As you correctly point out, dependency injection is the act of a class demanding its collaborators via constructor or setter injection. You could think of this as a coding technique. Inversion of control, on the other hand, is more of a design technique — a philosophy, if you will.

    In procedural programming (and procedural-style programming in OO languages), you generally have some kind of “command and control” philosophy. If you’re creating a house object that consists of three floor objects, which consist of some number of room objects each, you create a house object whose constructor instantiates three floor objects, each of whose constructor, in turn, instantiates room objects.

    When you invert control, you’re inverting command and control paradigm. With IoC, when I go to instantiate a house, it doesn’t take care of all of its details for me. Instead, it says, via its constructor (and dependency injection), “you can’t instantiate me without some floors”. So, you go to instantiate the floors and they say “nope, not without some rooms”. Now, in this “inverted” style, our house doesn’t control the creation of the rooms – it leaves that up to someone else and it expresses instead, only what it will do with the rooms it’s given. This is desirable because, by flipping command and control on its head, you have better seams for reasoning about and testing the code — it’s easier to deconstruct things into components.

    So, to summarize, inversion of control is the philosophy and dependency injection is the means by which it’s achieved.

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

Sidebar

Related Questions

Possible Duplicates: Difference between Dependency Injection (DI) & Inversion of Control (IOC) Inversion of
Possible Duplicate: What is Inversion of Control? Okay, I'm new to this site and
Possible Duplicate: What is Inversion of Control? I am not familiar with Inversion of
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: Hibernate - AnnotationConfiguration deprecated In version 3.2 of Hibernate, I could configure
Possible Duplicate: C++ templates that accept only certain types For example, if we want
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Possible Duplicate: .NET - What’s the best way to implement a catch all exceptions
Possible Duplicate: What Ruby IDE do you prefer? I've generally been doing stuff on

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.