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

Can I use ioc container for function not constructor?

This is my main class: class Human{ public: Human(IHat *hat){ hat->ChooseHat(); } }; Here is classes that are about hats: class IHat{ public: virtual void ChooseHat() = 0; }; class PirateHat : public IHat{ public: void…
2
votes
1 answer

method selector on one of many interceptors for a service registered in Castle.Windsor

Using Castle.Windsor, how would I go about adding a IProxyGenerationHook or selector for one of several interceptors defined for a specific service. For example consider the following component registration: container.Register( _ …
2
votes
1 answer

How to use Dependency Injection for creating ViewModels in a Master-Detail view

I'm building a Silverlight app using Jounce for my MVVM. I have a CustomerListViewModel (plural) which has a collection of CustomerViewModel objects (single). I'm using Ninject for dependency injection, because my ViewModels will be depending on…
Peter
  • 13,733
  • 11
  • 75
  • 122
2
votes
4 answers

Unity wraps exception to the ResolutionFailedException. How to avoid?

I want to know, is there the possibility to ask Unity "do not wrap any user exceptions at resolve time"? Really, why Unity do wrappings to ResolutionFailedException? It is changing "construction service contract", IMHO the fact of objects…
Roman Pokrovskij
  • 9,449
  • 21
  • 87
  • 142
2
votes
1 answer

Is it possible to customize DryIOC type matching to workaround embedded Interop COM assemblies type mismatch?

We are currently working on a Prism project using DryIoc as the backing container and we are running into problems with the embedding of Interop assemblies for our COM interop. In the past, when we had issues like this, for instance, with…
2
votes
1 answer

Keeping dependency inject component out of main code base

I have a MVC app that uses ninject to inject service dependencies into controllers and it works well. However I also have some domain objects that require these services in their constructors and I want to resolve these dependencies using ninject,…
Mike Hanrahan
  • 1,192
  • 8
  • 18
2
votes
1 answer

How to Make Alternative Use of Interfaces for Wcf Contracts

Lets say I have 3 assemblies, Example.Core, Example.Contracts, Example.WcfServices. In my contracts assembly I define an interface and add some operation, e.g. ICalculator, which has operation Add(double a, double b). In my WcfServices assembly I…
Mike Hanrahan
  • 1,192
  • 8
  • 18
2
votes
1 answer

How to configure dependency injection container with Func?

BusinessAction is used to represent an action that can be performed by a user. Each action is related to the specific entity, so if for example, that entity is Order, business actions could be CancelOrder, IssueRefund, etc. public abstract class…
gzsun
  • 209
  • 1
  • 11
2
votes
1 answer

Scoped Unit of Work Resolution in Prism Xamarin with DryIoc

In a Prism Xamarin app with DryIoc as container, I have a Unit of Work which is referenced by several other components which are then referenced from view models. It looks something like this (interface declarations skipped for briefness): public…
Vladimir
  • 1,425
  • 16
  • 31
2
votes
2 answers

Resolving with rules in Unity?

I have interface IRepository that maps to the class GenericRepository in unity. IOC.Container.RegisterType(); (GenericRepository takes a ObjectContext (Entity Framework context) to perform its data actions) The…
Vaccano
  • 78,325
  • 149
  • 468
  • 850
2
votes
2 answers

Inversion of Control, Spring Framework - system of global instances

Is inversion of control essentially just retrieving a set of already instantiated objects? In theory. I guess more granular details as implemented by IoC frameworks like Spring have a lot more functionality, but in theory it seems like IoC…
Berlin Brown
  • 11,504
  • 37
  • 135
  • 203
2
votes
1 answer

Circular component dependency detected while activating Autofac .NET Core Web API

I have a problem with IAfterSaleService interface and AfterSaleService Class and I used autofac IoC for these cs files. However while constructor injection ı made is working for some interface, aftersaleservice is not working for some constructor…
2
votes
4 answers

Problems with MVC Controllers + Dependency Injection (Ninject) in medium trust

I want to use dependency injection in an medium trust environment. To that aim I picked Ninject as Iv been told its light weight. How do I set-up injection into the controllers? When I tried to create a custom controller factory: public class…
Dan
  • 29,100
  • 43
  • 148
  • 207
2
votes
2 answers

NestJS: UseGuards Doesn't Use Dependency Injection - Can't Override Guard

Current behavior The documentation states here that: ...we passed the RolesGuard type (instead of an instance), leaving responsibility for instantiation to the framework and enabling dependency injection. So I'm expecting to "override" a guard…
Dimdum
  • 322
  • 2
  • 15
2
votes
2 answers

How to yield control to a calling method

Say I have a Task object, with an Execute method. This method has one to several steps, each of which requires a user to click a 'Continue' button, e.g. when Execute is invoked, the Task tells it's container (a Windows form in this case) to display…
ProfK
  • 49,207
  • 121
  • 399
  • 775