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
60
votes
1 answer

how to use MVVMLight SimpleIoc?

I'm revamping my software which has messy Messenger.Default(...) bits. Is there any cheat sheet to know MVVMLight SimpleIoc usage (not general IoC description)?
Youngjae
  • 24,352
  • 18
  • 113
  • 198
59
votes
1 answer

Generic Type in constructor

I have a Generic Type Interface and want a constructor of an object to take in the Generic Interface. Like: public Constructor(int blah, IGenericType instance) {} I want the code that creates this object to specify the IGenericType (use…
CSharpAtl
  • 7,374
  • 8
  • 39
  • 53
57
votes
5 answers

Is dependency injection useful in C++

C# uses Dependency Injection (DI) a lot to have a lossless and testable platform. For this, I need an interface and maybe a DI or Inversion of Control (IoC) container for resolving my instances. But how do you do this in C++? I've read a little bit…
56
votes
3 answers

MEF (Managed Extensibility Framework) vs IoC/DI

What problems does MEF (Managed Extensibility Framework) solves that cannot be solved by existing IoC/DI containers?
alex
  • 74,215
  • 9
  • 49
  • 57
51
votes
4 answers

What's the Python version for “Code against an interface, not an object”?

Inspired by a great question (and bunch of great answers) from here. Does the statement "Code against an interface, not an object" have any significance in Python? I'm looking for answers like the ones in the Original Question but with Python…
Jeffrey Jose
  • 1,992
  • 2
  • 16
  • 21
50
votes
2 answers

Abstract factory pattern on top of IoC?

I have decided to use IoC principles on a bigger project. However, i would like to get something straight that's been bothering me for a long time. The conclusion that i have come up with is that an IoC container is an architectural pattern, not a…
Sergey
50
votes
4 answers

Abstractions should not depend upon details. Details should depend upon abstractions?

In past couple of days, I have read about quite a lot about dependency injection/inversion of control/inversion of dependency. I think that, now my understanding of the concept is much better. But I still don't get the following from wikipedia: A.…
Sandbox
  • 7,910
  • 11
  • 53
  • 67
50
votes
5 answers

How to avoid anemic domain models, or when to move methods from the entities into services

I have a common scenario that I am looking for some guidance from people more experienced with DDD and Domain Modeling in general. Say I start out building a blog engine, and the first requirement is that after an Article is posted, users can start…
Matt Hidinger
  • 1,743
  • 16
  • 16
49
votes
2 answers

Design - Where should objects be registered when using Windsor

I will have the following components in my application DataAccess DataAccess.Test Business Business.Test Application I was hoping to use Castle Windsor as IoC to glue the layers together but I am bit uncertain about the design of the gluing. My…
Fredrik Jansson
  • 3,764
  • 3
  • 30
  • 33
48
votes
3 answers

NInject: Where do you keep your reference to the Kernel?

I'm using NInject on a new web application and there are two things that are unclear to me: Don't I need to keep a reference to the Kernel around (Session/App variable) to insure that GC doesn't collect all my instances? For example, if I specify…
JC Grubbs
  • 39,191
  • 28
  • 66
  • 75
47
votes
7 answers

Dependency Inversion Principle (SOLID) vs Encapsulation (Pillars of OOP)

I was recently having a debate about the Dependency Inversion Principle, Inversion of Control and Dependency Injection. In relation to this topic we were debating whether these principles violate one of the pillars of OOP, namely Encapsulation. My…
47
votes
2 answers

Difference between MEF and IoC containers (like Unity, Autofac, SMap, Ninject, Windsor.Spring.net, etc.)

I have been searching about the dependency injection and read a few articles. But still I am unable to find out the difference between MEF and other IoC's. So, my question is this: In which situation should I prefer to use a MEF or IoC…
46
votes
1 answer

Simple Injector vs Hiro vs Autofac

I'm new to DI and IoC and I'm trying to decide which IoC container to learn. I've seen several performance comparisons in which the three containers referenced seem to perform very well. However, I have found no feature comparisons that included…
46
votes
9 answers

Examples of IoC Containers

Does anyone have good examples of IoC containers (preferably in c#) and how and why to use them ? I have checked out the wiki page and Ayende's example, but I don't quite get the concept yet. And when and where should I use an IoC container ?
Morph
  • 1,719
  • 1
  • 18
  • 23
46
votes
3 answers

Translate ninject ISecureDataFormat binding to Autofac

I am migrating a large codebase from Ninject to Autofac and am struggling on one of the bindings that I believe is causing an activation error based on some of my debugging. Ninject: Bind>() …
O'Mutt
  • 1,557
  • 1
  • 13
  • 27