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
28
votes
5 answers

Usage of IoC Containers; specifically Windsor

I think the answer to this question is so obivous that noone has bothered writing about this, but its late and I really can't get my head around this. I've been reading into IoC containers (Windsor in this case) and I'm missing how you talk to the…
Andrew Bullock
  • 36,616
  • 34
  • 155
  • 231
28
votes
4 answers

IOC - Should util classes with static helper methods be wired up with IOC?

Just trying to still get my head around IOC principles. Q1: Static Methods - Should util classes with static helper methods be wired up with IOC? For example if I have a HttpUtils class with a number of static methods, should I be trying to pass it…
Greg
  • 34,042
  • 79
  • 253
  • 454
28
votes
3 answers

Could not load file or assembly System.Web.WebPages.Razor, , Version=3.0.0.0 or one of its dependencies

I am using MVC 5, WCF and Unity framework in my application. I am getting below error when I run WCF service: Server Error in '/' Application. Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral,…
user2934829
  • 667
  • 1
  • 7
  • 10
28
votes
5 answers

Castle.Windsor lifestyle depending on context?

I have a web application where many components are registered using .LifestylePerWebRequest(), now I've decided to implement Quartz.NET, a .NET job scheduling library, which executes in separate threads, and not the Request thread. As such,…
bevacqua
  • 47,502
  • 56
  • 171
  • 285
27
votes
1 answer

What does AsSelf do in autofac?

What is AsSelf() in autofac? I am new to autofac, what exactly is AsSelf and what are the difference between the two below? builder.RegisterType().AsSelf().As(); builder.RegisterType().As(); Thank you!
spspli
  • 3,128
  • 11
  • 48
  • 75
27
votes
7 answers

How to apply decorators with ASP.NET Core Dependency Injection

On an ASP.NET MVC 5 application I have the following StructureMap configuration: cfg.For(typeof(IRequestHandler<,>)).DecorateAllWith(typeof(MediatorPipeline<,>)); Does anyone know how to do this configuration with ASP.NET Core IOC?
Miguel Moura
  • 36,732
  • 85
  • 259
  • 481
27
votes
4 answers

Defining the same Spring bean twice with same name

Is having two definition for a bean (with same name and class) valid in Spring IOC ? I am having two bean definition files included in web.xml. See the sample below. applicationContext-beans1.xml
hop
  • 2,518
  • 11
  • 40
  • 56
27
votes
7 answers

IoC, Where do you put the container?

I'm using castle windsor for a pet-project I'm working on. I'm starting to notice that I need to call the IoC container in different places in my code to create new objects. This dependency on the container makes my code harder to maintain. There…
Mendelt
  • 36,795
  • 6
  • 74
  • 97
26
votes
3 answers

ASMX Dependency Injection and IoC

So i have gotten stuck while trying to get my asmx webservice to use dependency injection and using an IoC to do it. I want my webservice to be able to use my internal business layer services. The webservice is to be used by an external client from…
limlim
  • 395
  • 1
  • 6
  • 14
26
votes
6 answers

Best Practices for IOC Container

I'm using the Unity IOC container and I'm just wondering what is the best best way to access the container for multiple classes. Should every class have an IUnityContainer member and then pass the container in by constructor? Should there be a…
Ryu
  • 8,641
  • 10
  • 65
  • 98
26
votes
2 answers

How to register many for open generic in Autofac

I'm new to Autofac (not to DI). Here is the situation: I have these interfaces: public interface IQuery : IQuery { } public interface IQueryHandler where TQuery : IQuery { TResult Handle(TQuery…
amiry jd
  • 27,021
  • 30
  • 116
  • 215
26
votes
2 answers

Multiple implementations for one interface with DI

Right now I'm trying to teach myself the Dependency Injection pattern with the IOC-container from Autofac. I've come up with a very simple example, which is presented below. Although the example is simple, I fail to get it working properly. Here are…
Boris
  • 8,551
  • 25
  • 67
  • 120
25
votes
4 answers

How do I pass a parameter to the constructor using Simple Injector?

Does Simple Injector allow you to pass parameters to constructor when you resolve? I'd like to know if both these frameworks do what Unity's ResolverOverride or DependencyOverride both do.
Ray
  • 4,679
  • 10
  • 46
  • 92
24
votes
7 answers

What is Component-Driven Development?

Component-Driven Development term is starting to get used widely, esp. in connection with Inversion of Control. What is it? What problems does it solve? When is it appropriate and when not?
Rinat Abdullin
  • 23,036
  • 8
  • 57
  • 80
24
votes
3 answers

Recommended IoC framework for iOS?

Can anyone recommend a good IoC framework for iOS to facilitate dependency injection? The only one I've found so far is Objection Framework which apparently is similar to Guice (which unfortunately is unfamiliar to me). Is this one a common choice…
Clafou
  • 15,250
  • 7
  • 58
  • 89