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
24
votes
6 answers

FactoryBeans and the annotation-based configuration in Spring 3.0

Spring provides the FactoryBean interface to allow non-trivial initialisation of beans. The framework provides many implementations of factory beans and -- when using Spring's XML config -- factory beans are easy to use. However, in Spring 3.0, I…
Andrew Newdigate
  • 6,005
  • 3
  • 37
  • 31
24
votes
8 answers

Setter / property injection in Unity without attributes

I am working on a project where the Unity framework is used as the IoC container. My question relates to injecting an optional dependency (in this case a logger) into several classes using property- or setter injection. I do not want to clutter the…
LittleBoyLost
  • 518
  • 2
  • 4
  • 11
24
votes
3 answers

IoC and ASP.NET MVC, where does it all begin?

I see "IoC" and "DI" mentioned pretty much everywhere for ASP.NET MVC. While I'm well aware of ... 'kind of' what these are, it's one of those almost ambiguous, amorphous floating concepts that seems to have either passed me by, or I'm just not…
Ciel
  • 17,312
  • 21
  • 104
  • 199
24
votes
3 answers

Autofac None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder'

None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'LMS.Services.Security.EncryptionService' can be invoked with the available services and parameters: Cannot resolve parameter…
24
votes
1 answer

Using Entity Framework with Castle Windsor

I use the Entity Framework database-first approach to generate a DbContext / POCO model for an MVC application. I want to avoid having dependencies on DbContext in my controllers to enable me to switch to another persistence provider as I need to…
24
votes
4 answers

IoC (Ninject) and Factories

If I have the following code: public class RobotNavigationService : IRobotNavigationService { public RobotNavigationService(IRobotFactory robotFactory) { //... } } public class RobotFactory : IRobotFactory { public IRobot Create(string…
BuddyJoe
  • 69,735
  • 114
  • 291
  • 466
23
votes
1 answer

Autofac equivalent of Ninject's WhenInjectedInto()

So we're working on converting some projects at work from Ninject to Autofac, and we've stumbled on something really neat within Ninject that we can't figure out how to do in Autofac. In our application, we have an interface called ISession which…
23
votes
5 answers

Pros and Cons of Inversion of Control

Suppose I have a stream of [acme] objects that I want to expose via an API. I have two choices, callbacks and iterators. API #1: Callbacks // API #1 // This function takes a user-defined callback // and invokes it for each object in the…
kirakun
  • 2,770
  • 1
  • 25
  • 41
23
votes
4 answers

Correct use of Autofac in C# console application

I'm new using Autofac so my apologies for the noob question. I read every manual in Internet explaining the basics when using Autofac (or any other tool like Structuremap, Unity, etc). But all the examples that I found are basics. I need to know how…
23
votes
2 answers

Logging as a decorator vs. Dependency Injection - what if I need to log inside the class?

(I originally asked this question in this comment, but Mark Seemann asked me to create a new question instead.) I'm starting a new app (.NET Core, if that matters), and right now I'm trying to decide how exactly to do logging. The general consensus…
23
votes
3 answers

Is there a good/proper way of solving the dependency injection loop problem in the ASP.NET MVC ContactsManager tutorial?

If you don't know what I'm talking about either go through the tutorial and try to add dependency Injection yourself or try your luck with my explanation of the problem. Note: This problem isn't within the scope of the original tutorial on ASP.NET.…
22
votes
3 answers

Unity not using the default constructor of the class

I have this class : public class Repo { public Repo() : this(ConfigurationManager.AppSettings["identity"], ConfigurationManager.AppSettings["password"]) { } public Repo(string identity,string password) { //Initialize…
Attilah
  • 17,632
  • 38
  • 139
  • 202
22
votes
2 answers

What are "High-level modules" and "low-level modules" (in the context of Dependency inversion principle)?

I was reading Wikipedia's definition of Dependency inversion principle, and it uses two terms High-level modules and low-level modules, which I wasn't able to figure out. What are they and what does Dependency inversion principle have to do with…
22
votes
4 answers

Register Container Itself Using Autofac

I was wondering is there's any side effect to registering the container within itself IContainer container; ContainerBuilder builder = new ContainerBuilder(); container = builder.Build(); builder.RegisterInstance(container).As(); and…
Scarnet
  • 490
  • 2
  • 6
  • 19
22
votes
3 answers

Inversion of Control < Dependency Injection

I'm getting the feeling that there's is not such thing as inversion of control or rather the correct term is dependency injection. Am I wrong to assume this? I've been trying to define IoC for my own sake. In doing so I've learned a great deal about…
John Leidegren
  • 59,920
  • 20
  • 131
  • 152