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

How do inject array of implementations into constructor in PHP

How do inject array of implementations into class through constructor. I am sharing the link which is c#. I want to achieve the same in php. How to achieve same in php. public interface IFoo { } public class FooA : IFoo {} public class FooB : IFoo…
user1844634
  • 1,221
  • 2
  • 17
  • 35
2
votes
0 answers

Unity DI Container Random Index Out of Bounds Error

We have a ASP.NET API that gets many requests per day, up in the hundreds of thousands per day. Under high load, I have noticed that about 5% of requests will result in an error. Below is the stack trace we see for each one of these…
2
votes
1 answer

How to containerize a builder class in Aura.Di?

Without a DI container, you would normally do something like this: $foo = (new FooBuilder) ->setA('a') ->setB('b') ->build(); // where $foo becomes an instance of Foo class How do you register/containerize something like that in Aura.Di?
IMB
  • 15,163
  • 19
  • 82
  • 140
2
votes
1 answer

dependency injection using unity on custom session store provider

I made a custom SessionStateStore provider, however the dependencies were not resolving. I used Unity for DI. I googled a lot about this problem and got some useful hints, but still I can't get it right. the providers are constructed and managed…
2
votes
1 answer

Does using DependencyResolver incur a performance hit?

I found a few articles outlining the reason why the DependencyResolver in C# MVC should be avoided But I also found a pattern of injecting a "base dependency" into a constructor, and that class essentially hold all instances the app's dependencies,…
Ninjanoel
  • 2,864
  • 4
  • 33
  • 53
2
votes
1 answer

Autofac RegisterAssemblyTypes multiple times

I have WPF application with multiple view models and a corresponding class hierarchy. Now I use Autofac as IoC framework. My structure looks simplified like this: public class ViewModelBase {} public class ToolItemViewModel :…
Franz Gsell
  • 1,425
  • 2
  • 13
  • 22
2
votes
1 answer

How do I use InstanceScope.HttpSession in StructureMap?

I'm trying to use StructureMap's InstanceScope.HttpSession feature and I'm running into problems. I have the following method I'm using for testing: public static class StructureMapTest { public static T Get() { …
JC Grubbs
  • 39,191
  • 28
  • 66
  • 75
2
votes
2 answers

Implementing OnePerSessionBehavior in NInject

I'd like to create a OnePerSessionBehavior for NInject (v1.0) and I've mostly got it working. The only issue that remains is how to pass in fresh arguments using .WithArguments() as each new session asks for something from the container. Right now…
JC Grubbs
  • 39,191
  • 28
  • 66
  • 75
2
votes
2 answers

Any IOC framework to recommend under c# 4.0?

I am wondering if anyone can recommend IOC framework which can work under c# 4.0? Also, does .Net framework 4.0 natively support IOC?
user705414
  • 20,472
  • 39
  • 112
  • 155
2
votes
2 answers

StructureMap creating instance

I have the concrete types for interfaces configured at startup, but I want to create instances of the concrete type at runtime with setting properties or setting different values in the constructor. All the creating of instances I see have the…
CSharpAtl
  • 7,374
  • 8
  • 39
  • 53
2
votes
6 answers

What DI/IoC framework should I learn next?

I've used Spring and Spring.NET quite a bit, but I would like to see what else is out there. Can anyone recommend a good Java or .NET framework that I could try to learn?
Andy White
  • 86,444
  • 48
  • 176
  • 211
2
votes
1 answer

IoC - Where does Control "Invert" To? (Where does it go?)

Basic theory question alert! Its about IoC. I was reading about IoC, and realized how i am not fully comfortable about the exact meaning of the term. Then, I came across a specific Answer about IoC, which made me realize, that IoC is not just about…
fourbeatcoder
  • 1,159
  • 3
  • 13
  • 21
2
votes
1 answer

How to list all the managed @Component in Spring Boot?

I am trying to list all the managed Components in a Spring Boot application using a ListableBeanFactory interface as illustrated in How to Get All Spring-Managed Beans? @SpringBootApplication public class Application { private static…
j.xavier.atero
  • 506
  • 2
  • 10
  • 25
2
votes
3 answers

Mysterious authentication error connecting from Dapper but works from EF 6 - same ConnectionString

We have services and repositories loaded by IoC. /* registration in the service class for repository */ container.Register(); /* registration in GUI app from service class and Form class for constructor…
2
votes
1 answer

How do you set up StructureMap to use a Singleton with the Use<>.For<> syntax

I am using StructureMap with MVC3 I want to set it up to use a few of the objects as Singletons or to give them a Per Request life. All of the examples I see out there are for an older syntax of StructureMap as when I try out the example I see…
runxc1 Bret Ferrier
  • 8,096
  • 14
  • 61
  • 100