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
16
votes
2 answers

Is this a good example of the "Bastard injection anti-pattern"?

I see lead developers writing code like this and upon reading Mark Seemann's book "Dependency Injection in .NET" I'm wondering if the specific "new" is "foreign", thus "Bastard Injection"?? public class SessionInitServiceManager { protected…
Tom Stickel
  • 19,633
  • 6
  • 111
  • 113
16
votes
5 answers

Spring bean injection in a main method class

I have a web application with spring 3.0. I need to run a class with main method from a cron that uses beans defined in appcontext xml(using component scan annocations). I have my main class in same src directory. How can I inject beans from web…
16
votes
1 answer

Castle Windsor passing constructor parameters

I have an IAddress class with a few properties. I then have a concrete type that implements this interface. This concrete type has a couple of different constructors I could use. How can I pass parameter values to one of these constructors at…
16
votes
3 answers

Using Autofac as a service locator

I'm using Autofac to handle dependency injection in my application. However, I have one component that does some reflection magic at runtime and I don't know at compile-time what dependencies it will need. Ordinarily, I would just have this…
David Pfeffer
  • 38,869
  • 30
  • 127
  • 202
16
votes
5 answers

DAL -> BLL <- GUI + composition root. How to setup DI-bindings?

I have made a three-layer application with refrences going as described in this answer: DAL with Repositories -> BLL with services and IRepository <- Asp.net mvc-app To get this running with dependency injection I see a few options: 1. Add a…
Grastveit
  • 15,770
  • 3
  • 27
  • 36
16
votes
2 answers

IoC/DI in the face of winforms and other generated code

When using dependency injection (DI) and inversion of control (IoC) objects will typically have a constructor that accepts the set of dependencies required for the object to function properly. For example, if I have a form that requires a service to…
16
votes
3 answers

Symfony how to get container in my service

I have symfony project and inside this project, I have big own service which is huge and complicated with own dependencies etc... And I wanna create facade for this service with purpose to use my service in controllers like: $myService =…
cn007b
  • 16,596
  • 7
  • 59
  • 74
16
votes
1 answer

MVC3 + Ninject - How to?

I've just started playing with IoC containers and therefore chosed Ninject. After several hours of sweat and tears I still cant figure out how to setup my MVC3 application with Ninject. So far I have: Global.asax.cs public class MvcApplication :…
ebb
  • 9,297
  • 18
  • 72
  • 123
16
votes
13 answers

Which patterns for loose coupling do you use most?

Lately I have seen a lot of blog posts concerning how to build loosely coupled applications. Which patterns do you use most when creating loosely coupled applications? Dependency Injection? Inversion of Control?
Fossmo
  • 2,862
  • 4
  • 25
  • 47
16
votes
1 answer

AddAllTypesOf vs ConnectImplementationsToTypesClosing

I'm curious as to the difference between these two methods. I'm implementing a decorator pattern with open generics and whether I use AddAllTypesOf or ConnectImplementationsToTypesClosing it doesn't matter, I get the same functionality. public class…
16
votes
3 answers

How to define a default constructor by code using StructureMap?

I can't figure out how to define the default constructor (when it exists overloads) for a type in StructureMap (version 2.5) by code. I want to get an instance of a service and the container has to inject a Linq2Sql data context instance into it. I…
Cyril Bioley
  • 391
  • 1
  • 3
  • 9
16
votes
2 answers

What is the difference between Inversion of Control and Dependency injection in C++?

I've been reading recently about DI and IoC in C++. I am a little confused (even after reading related questions here on SO) and was hoping for some clarification. It seems to me that being familiar with the STL and Boost leads to use of dependency…
rlbond
  • 65,341
  • 56
  • 178
  • 228
16
votes
1 answer

When to use an IOC container?

I'm trying to understand when I should use a container versus manually injecting dependencies. If I have an application that uses a 1-2 interfaces and only has 1-2 concrete implementations for each interface, I would lean towards just handling that…
nivlam
  • 3,223
  • 4
  • 30
  • 39
16
votes
1 answer

What are "ForwardedTypes" in the context of Castle Windsor component registration?

As the subject says, really! What do they do?
Peter Mounce
  • 4,105
  • 3
  • 34
  • 65
16
votes
12 answers

Are there any inversion of control frameworks for javascript?

Are there any inversion of control frameworks for javascript? The closest answer available on stackoverflow that I could find is here: What is the right way to wire together 2 javascript objects? . It looks like a great start, but I thought I'd be…
Frank Schwieterman
  • 24,142
  • 15
  • 92
  • 130