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

In ServiceStack what is the proper way to get the container

I'm currently attempting to use ServiceStack in a SignalR application that I am writing that is part of a large MVC 4.5 application. I currently have a class in the App_Start folder that is starting my Hub. My question is how do I get a reference to…
msarchet
  • 15,104
  • 2
  • 43
  • 66
16
votes
3 answers

Unity - Inject different classes for the same interface

I have one interface: IFoo Two classes implementing that interface: FooOne and FooTwo And two classes ClassOne and ClassTwo receiving an IFoo parameter in the constructor. How I configure unity so ClassOne receives a FooOne instance and ClassTwo…
pomber
  • 23,132
  • 10
  • 81
  • 94
16
votes
2 answers

Getting Started with Unity Framework

Could anyone recommend some good resources for getting started with the Unity framework? I've downloaded the source from Codeplex and got it to compile. So now I've got a set of compiled binaries, where do I go next? I understand the principles of…
Steve
  • 2,073
  • 4
  • 27
  • 39
15
votes
5 answers

How to Decouple IoC Framework Implementation

I've been learning IoC, Dependency Injection etc. and enjoying the process. The benefits of decoupling and programming to interfaces are, to me, a no-brainer. However, I really don't like binding myself to a specific framework like Unity or Autofac…
15
votes
5 answers

Autofac in web applications, where should I store the container for easy access?

I'm still pretty new to using Autofac and one thing I miss in the documentation and examples is how to make it easy to get to the configured container from different places in a web application. I know I can use the Autofac controller factory to…
15
votes
7 answers

What is Inversion of Control (IoC)?

Can someone guide me to some basic tutorials on inversion of control (IoC)? (preferably .net/c#). I need some hands on code to wrap my head around it :)
blahblah
15
votes
5 answers

.NET Core Exception: A circular dependency was detected for the service of type

Recently I asked a question about software architecture Should service call another service or repository directly? After that answer, I reorganized and refactored my application. In a simple way, my services call each other, StudentService requires…
15
votes
2 answers

C# Difference between factory pattern and IoC

Possible Duplicate: Dependency Injection vs Factory Pattern Can someone please explain (with SIMPLE examples) of the difference between the factory pattern and Inversion of Control pattern. Preferably using .NET2.0
Eminem
  • 7,206
  • 15
  • 53
  • 95
15
votes
1 answer

What is the main difference between ContainerControlledLifetimeManager and HierarchicalLifetimeManager?

What is the general difference between ContainerControlledLifetimeManager and HierarchicalLifetimeManager? I know that ContainerControlledLifetimeManager represent singleton that is DI container will create a new instance for each type which needed…
15
votes
2 answers

Best practices for dependency injection via constructor

Inversion of control is a value-proof technique which is used to modularize a system and decouple the components from each other. Low coupling is always an advantage: it simplifies automatic testing of the components and makes the code better…
manlio
  • 18,345
  • 14
  • 76
  • 126
15
votes
1 answer

How to use Automapper with unity dependancy injection?

I am planning to use Automapper with ASP.NET MVC solution and Unity DI. The video posted on automapper on how to use is very old and doesn't show how mapper can be used with dependency injection. Most of the examples on stackoverflow also uses…
LP13
  • 30,567
  • 53
  • 217
  • 400
15
votes
6 answers

IoC library compatible with MonoTouch?

Still getting familiar with the limits of MonoTouch. Is there an IoC/DI library that can be used with MonoTouch. Something like Ninject ideally?
15
votes
2 answers

Is this a typical use case for IOC?

My current application allows users to define custom web forms through a set of admin screens. it's essentially an EAV type application. As such, I can't hard code HTML or ASP.NET markup to render a given page. Instead, the UI requests an instance…
15
votes
1 answer

Entity Framework using Repository Pattern, Unit of Work and Unity

Using a combination provided from this example and this implementation I am trying to create a solution that decouples the UnitOfWork class from the individual repositories, as they violate the Open-Closed Principle, since every time you added a new…
15
votes
2 answers

Autofac - how to resolve Func for ISomething from Singleton where ISomething is InstancePerHttpRequest

I'm trying to use Autofac to inject dependencies into FluentValidation in an MVC 4 app. I think I've got the strategy worked out, but I'm getting stuck with resolving my per-request ISomething from a singleton. Here's the scenario: I've got a…
Tim Hardy
  • 1,654
  • 1
  • 17
  • 36