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

Dependency Injection Unity - Conditional Resolving

Conditional resolving is the last thing I don't understand at the moment. Lets say we have an interface IAuthenticate: public interface IAuthenticate{ bool Login(string user, string pass); } Now I have two types of authentication. Twitter…
sensei
  • 7,044
  • 10
  • 57
  • 125
21
votes
5 answers

The type String cannot be constructed

I'm using Web.api and Unity and I am getting the following error when trying to open the default "help" area: [InvalidOperationException: The type String cannot be constructed. You must configure the container to supply this…
21
votes
4 answers

Dependency Injection as a Language Feature?

Are there any existing modern-day programming languages that explicitly have dependency injection as a language feature, and if so, are there any examples of how such programming languages use their syntax to separate program dependencies from their…
plaureano
  • 3,139
  • 6
  • 30
  • 29
20
votes
4 answers

Auto-register all interfaces with Unity

Using Unity, I'd like to automatically register all interface/class combinations in an assembly based on the following convention: INameOfObject > NameOfObject StructureMap does that when the default conventions are enabled. I wrote the following…
David
  • 3,736
  • 8
  • 33
  • 52
20
votes
1 answer

SignalR Hubs Clients are null when firing event

I've written a generic hubs which I'm having some issues with so to debug it I've decided to make a simple connection count like so: public class CRUDServiceHubBase : Hub, ICRUDServiceHubBase { public const string CreateEventName =…
johnny 5
  • 19,893
  • 50
  • 121
  • 195
20
votes
3 answers

Dependency Injection composition root and decorator pattern

I'm getting StackoverflowException's in my implementation of the decorator pattern when using dependency injection. I think it is because I'm "missing" something from my understanding of DI/IoC. For example, I currently have CustomerService and…
20
votes
4 answers

What does decoupling two classes at the interface level mean?

Lets say we have class A in package A and class B in package B . If object of class A has reference to class B, then the two classes are said to have coupling between them. To address the coupling, it is recommended to define an interface in…
Sarit Adhikari
  • 1,344
  • 2
  • 16
  • 28
20
votes
2 answers

List all types registered with a Castle Windsor container instance

What's the easiest way of programatically listing registered types in Castle Windsor? Thanks
UpTheCreek
  • 31,444
  • 34
  • 152
  • 221
20
votes
3 answers

Lazy Dependency Injection

I have a project where the Ninject is used as IoC container. My concern is that a lot of classes have such kind of constructors: [Inject] public HomeController( UserManager userManager, RoleManager roleManager, BlahblahManager blahblahManager)…
xwrs
  • 1,287
  • 3
  • 16
  • 29
20
votes
3 answers

2 beans with same name but in different packages; how to autowire them?

I have an application that has 2 beans with the same name, but which are in different packages. My Spring application fails because it cannot decide on which bean to take. Is there any solution for this? The beans do not currently implement specific…
Marco
  • 15,101
  • 33
  • 107
  • 174
19
votes
2 answers

Specifying instance for registration of a component with Castle Windsor

I have what is probably a simple question here about Castle Windsor, which I haven't been using for very long. I'm trying to register a service with a specific instance that will be the singleton implementation of the service. The container cannot…
19
votes
5 answers

How to register multiple IDbConnectionFactory instances using Funq in ServiceStack.net

How would you go about registering diferent IDbConnectionFactory instances in Funq and then access them directly within your services? Do named instances somehow come into play here? Is this the best approach to take when using different…
Jeff Mitchell
  • 1,459
  • 1
  • 17
  • 33
19
votes
2 answers

How to use Ninject Conventions extension without referencing Assembly (or Types within it)

Sorry in advance for the long question, it's long because I've been digging at this all day. The general problem: I have an ASP.Net MVC2 application with the following projects: MyApp.Web, MyApp.Services, MyApp.Data. We code to interfaces and…
quentin-starin
  • 26,121
  • 7
  • 68
  • 86
19
votes
4 answers

How do I correctly use Unity to pass a ConnectionString to my repository classes?

I've literally just started using the Unity Application Blocks Dependency Injection library from Microsoft, and I've come unstuck. This is my IoC class that'll handle the instantiation of my concrete classes to their interface types (so I don't have…
19
votes
10 answers

MVC 4 Web Api Controller does not have a default constructor?

Here is the trace: An error has occurred. Type 'ProjectName.Web.Api.Controllers.ContinentsController' does not have a default constructor
Komengem
  • 3,662
  • 7
  • 33
  • 57