Questions tagged [inversion-of-control]

Inversion of control (IoC) is an abstract principle describing an aspect of some software architecture designs in which the flow of control of a system is inverted in comparison to procedural programming.

In traditional programming the flow of the business logic is controlled by a central piece of code, which calls reusable subroutines that perform specific functions. Using Inversion of Control this "central control" design principle is abandoned. The caller's code deals with the program's execution order, but the business knowledge is encapsulated by the called subroutines. In practice, Inversion of Control is a style of software construction where reusable generic code controls the execution of problem-specific code. It carries the strong connotation that the reusable code and the problem-specific code are developed independently, which often results in a single integrated application. Inversion of Control as a design guideline serves the following purposes:

  • There is a decoupling of the execution of a certain task from implementation.
  • Every system can focus on what it is designed for.
  • The systems make no assumptions about what other systems do or should do.
  • Replacing systems will have no side effect on other systems.

Dependency injection and Inversion of Control are closely related. The difference between them is discussed in this question.

Wikipedia: Inversion of Control

Related Patterns

4379 questions
2327
votes
23 answers

What is a JavaBean exactly?

I understood, I think, that a "Bean" is a Java-class with properties and getters/setters. As much as I understand, it is the equivalent of a C struct. Is that true? Also, is there a real syntactic difference between a JavaBean and a regular class?…
2296
votes
39 answers

What is Inversion of Control?

Inversion of Control (IoC) can be quite confusing when it is first encountered. What is it? Which problem does it solve? When is it appropriate to use and when not?
702
votes
24 answers

Inversion of Control vs Dependency Injection

According to the paper written by Martin Fowler, inversion of control is the principle where the control flow of a program is inverted: instead of the programmer controlling the flow of a program, the external sources (framework, services, other…
Amumu
  • 17,924
  • 31
  • 84
  • 131
676
votes
23 answers

SqlException from Entity Framework - New transaction is not allowed because there are other threads running in the session

I am currently getting this error: System.Data.SqlClient.SqlException: New transaction is not allowed because there are other threads running in the session. while running this code: public class ProductManager : IProductManager { #region…
Keith Barrows
  • 24,802
  • 26
  • 88
  • 134
598
votes
30 answers

Why do I need an IoC container as opposed to straightforward DI code?

I've been using Dependency Injection (DI) for a while, injecting either in a constructor, property, or method. I've never felt a need to use an Inversion of Control (IoC) container. However, the more I read, the more pressure I feel from the…
Vadim
  • 21,044
  • 18
  • 65
  • 101
423
votes
18 answers

Why is IoC / DI not common in Python?

In Java IoC / DI is a very common practice which is extensively used in web applications, nearly all available frameworks and Java EE. On the other hand, there are also lots of big Python web applications, but beside of Zope (which I've heard should…
402
votes
12 answers

Which .NET Dependency Injection frameworks are worth looking into?

Which C#/.NET Dependency Injection frameworks are worth looking into? And what can you say about their complexity and speed.
pbreault
  • 14,176
  • 18
  • 45
  • 38
355
votes
10 answers

How to avoid Dependency Injection constructor madness?

I find that my constructors are starting to look like this: public MyClass(Container con, SomeClass1 obj1, SomeClass2, obj2.... ) with ever increasing parameter list. Since "Container" is my dependency injection container, why can't I just do…
JP Richardson
  • 38,609
  • 36
  • 119
  • 151
289
votes
22 answers

Do I need dependency injection in NodeJS, or how to deal with ...?

I currently creating some experimental projects with nodejs. I have programmed a lot Java EE web applications with Spring and appreciated the ease of dependency injection there. Now I am curious: How do I do dependency injection with node? Or: Do I…
Erik
  • 11,944
  • 18
  • 87
  • 126
236
votes
4 answers

Dependency Inject (DI) "friendly" library

I'm pondering the design of a C# library, that will have several different high level functions. Of course, those high-level functions will be implemented using the SOLID class design principles as much as possible. As such, there will probably be…
Pete
  • 11,313
  • 4
  • 43
  • 54
208
votes
5 answers

How to explain dependency injection to a 5-year-old?

What is a good way to explain dependency injection? I found several tutorials on Google, but none of them that would assume the reader is just a Java beginner. How would you explain this to a novice?
user198313
  • 4,228
  • 6
  • 24
  • 19
198
votes
5 answers

What is Castle Windsor, and why should I care?

I'm a long-time Windows developer, having cut my teeth on win32 and early COM. I've been working with .NET since 2001, so I'm pretty fluent in C# and the CLR. I'd never heard of Castle Windsor until I started participating in Stack Overflow. I've…
David Hill
  • 4,102
  • 2
  • 23
  • 19
164
votes
6 answers

Can someone explain Microsoft Unity?

I've been reading the articles on MSDN about Unity (Dependency Injection, Inversion of Control), but I think I need it explained in simple terms (or simple examples). I'm familiar with the MVPC pattern (we use it here), but I just can't really grasp…
161
votes
7 answers

How to resolve IOptions instance inside ConfigureServices?

Is it possible to resolve an instance of IOptions from the ConfigureServices method in Startup? The documentation explicitly says: Don't use IOptions or IOptionsMonitor in Startup.ConfigureServices. An inconsistent…
Muhammad Rehan Saeed
  • 35,627
  • 39
  • 202
  • 311
155
votes
15 answers

Dependency injection through constructors or property setters?

I'm refactoring a class and adding a new dependency to it. The class is currently taking its existing dependencies in the constructor. So for consistency, I add the parameter to the constructor. Of course, there are a few subclasses plus even more…
Niall Connaughton
  • 15,518
  • 10
  • 52
  • 48
1
2 3
99 100