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
46
votes
8 answers

IoC.Resolve vs Constructor Injection

I heard a lot of people saying that it is a bad practice to use IoC.Resolve(), but I never heard a good reason why (if it's all about testing than you can just mock the container, and you're done). now the advantages of using Resolve instead of…
Omu
  • 69,856
  • 92
  • 277
  • 407
46
votes
7 answers

Exception is: InvalidOperationException - The current type, is an interface and cannot be constructed. Are you missing a type mapping?

In my bootstrapper: namespace Conduit.Mam.ClientServices.Common.Initizliaer { public static class Initializer { private static bool isInitialize; private static readonly object LockObj = new object(); private static…
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
43
votes
3 answers

Koin how to inject outside of Android activity / appcompatactivity

Koin is a new, lightweight library for DI and can be used in Android as well as in standalone kotlin apps. Usually you inject dependencies like this: class SplashScreenActivity : Activity() { val sampleClass : SampleClass by inject() …
43
votes
1 answer

How does Reflection in Laravel work?

How does reflection in Laravel actually work? I tried to debug it to see how Laravel uses reflection in a controller's constructor or methods to resolve their dependencies and sub-dependencies and then and give it back to us. But I found it hard,…
Krystian Polska
  • 1,286
  • 3
  • 15
  • 27
43
votes
5 answers

Spring: Using builder pattern to create a bean

I use ektorp to connect to CouchDB. The way to build an ektorp HttpClient instance is to use builder pattern: HttpClient httpClient = new StdHttpClient.Builder() .host("mychouchdbhost") …
artemb
  • 9,251
  • 9
  • 48
  • 68
43
votes
4 answers

About multiple containers in spring framework

In a typical Spring MVC project there two "containers": One created by ContextLoaderListener and the other created by DispatchServlet. I want to know, are these really two IoC container instance?( I see two bean config files, one is root-context.xml…
lovespring
  • 19,051
  • 42
  • 103
  • 153
42
votes
7 answers

How do you reconcile IDisposable and IoC?

I'm finally wrapping my head around IoC and DI in C#, and am struggling with some of the edges. I'm using the Unity container, but I think this question applies more broadly. Using an IoC container to dispense instances that implement IDisposable…
Mr. Putty
  • 2,276
  • 1
  • 20
  • 20
42
votes
1 answer

Castle Windsor - IoC registration for open generic interfaces?

Does Castle Windsor permit registration of an open generic interface or do I need to register each possible typed instance separately? Example - the below with types T,Z fails upon compilation unless I separately specify T, Z with strong types. …
goldfinger
  • 1,105
  • 1
  • 20
  • 29
41
votes
4 answers

Unity 2.0 and handling IDisposable types (especially with PerThreadLifetimeManager)

I know that similar question was asked several times (for example: here, here,here and here) but it was for previous versions of Unity where the answer was dependent on used LifetimeManager class. Documentation says: Unity uses specific types that…
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
41
votes
6 answers

Onion vs. N-Layered Architecture

One thing beforehand: I arrive from an N-layered background. I have now spent quite a bit time getting my head around Onion Architecture and related Domain Driven concepts such as Hexagonal Architecture reading resources like Jeff Palermo's series…
41
votes
6 answers

What is AOP, Dependency Injection and Inversion Of Control in Simple English

I have tried to understand AOP, Dependency Injection and Inversion of Control SPRING related concepts but I am having hard time understanding it. Can anyone explain this in simple English ?
Rachel
  • 100,387
  • 116
  • 269
  • 365
41
votes
6 answers

Should logging infrastructure be injected when using IoC/DI if logging facade is used?

I am using Autofac as my IoC and from everything I have read on topic of DI teaches to use "constructor injection" to explicitly expose class dependencies... However, I am also using logging facade (Common.Logging) with Log4Net and have created…
zam6ak
  • 7,229
  • 11
  • 46
  • 84
40
votes
2 answers

Where exactly is the difference between IoC and DI

Possible Duplicate: Inversion of Control < Dependency Injection I always read IoC(Inversion of Control) and DI(Dependency Injection) in the same context. What is exactly the difference between IoC and DI? How does IoC differ from DI?
System.Data
  • 3,878
  • 7
  • 32
  • 40
40
votes
1 answer

Which IoC container is better with Prism.Forms

I am in the start of a new Prism.Forms project and I was wondering which of the various IoC containers (Autofac, Dryloc, Ninject or Unity) would be best to move forward with. I do not know if this is true, but I read somewhere that Unity is no…
Martin Robins
  • 6,033
  • 10
  • 58
  • 95
40
votes
1 answer

Is it possible to bind different interfaces to the same instance of a class implementing all of them?

I have the following (simplified) situation: I have two interfaces interface IAmAnInterface { void DoSomething(); } and interface IAmAnInterfaceToo { void DoSomethingElse(); } and a class implementing both: class IAmAnImplementation:…
Silas
  • 1,140
  • 11
  • 12