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

Register Decorator in Simple injector, common interface

I have a problem with a IoC with Simple Injector for Decorator.. How to register it in the Ioc Simple injector ? var data = new Data(); var test = new Data2Decorator (data, new Data1Decorator(data, new XxxData(data))) I tried it this way.…
A.Klim
  • 29
  • 3
2
votes
2 answers

Returning The Appropriate Concrete Type For Abstract Generic Type

I'm having a hard time with StructureMap configuration. I have a ValidationProvider that accepts a Func as its validation factory. I need to supply that using structure map so it would know what implementation of Validator (abstract) it should…
2
votes
2 answers

Where is Microsoft's useful documentation for IServiceCollection.Add(new ServiceDescriptor(...))?

I am working on an existing WebAPI project and inside public void ConfigureServices(IServiceCollection services) the IoC container is setup like so services.Add(new ServiceDescriptor(typeof(ISQLConnectionFactory), new…
robor
  • 2,969
  • 2
  • 31
  • 48
2
votes
0 answers

Creating WPF UserControls at runtime using Dependency Injection

I read a book about Dependency injection from Mark Seemann and Steven van Deursen and I'm trying to practice what I learned by programming a WPF application in C#. In my application I need to create custom UserControls at runtime based on what the…
2
votes
2 answers

.Net Core DI - multiple instances of the same type

First of all, I saw some topics similar to mine, however I think they don't really answer my issue. I am creating an application, which, depending on configuration can work in multiple modes. The app is a simple importer/exporter of data from…
2
votes
3 answers

Dependency Injection: Combine Constructor Injection benefit with Setter Injection benefits?

I'm annoyed to have to pass plumbing objects through Constructor because I'd like to reserve constructor arguments for business entities or values to pass. So I'd like to pass by Setters but my object which contains the dependencies should not be…
user310291
  • 36,946
  • 82
  • 271
  • 487
2
votes
5 answers

Realisticly why would I use duck-typing or inversion of control?

I'm just beginning to learn about Duck-typing, and Inversion of Control. In practical real world examples why would I want to incorporate these concepts into my code?
CodingIsAwesome
  • 1,946
  • 7
  • 36
  • 54
2
votes
1 answer

IoC - resolve WPF windows with injected object parameters

My first attempt on using an IoC container. A program has a number of different type of windows that are typically opened through a menu in MainWindow. However, in principle it could also be further down the chain. These windows usually need…
bretddog
  • 5,411
  • 11
  • 63
  • 111
2
votes
1 answer

How do I create Tagged Litetimes in Simple Injector?

What I want is Simple Injector's equivalent of Autofac's tagged lifetimes: I've read Simple Injector's documentation. The most probable way to accomplishing this is by using Simple Injector's custom lifestyles: But the documentation on it is very…
2
votes
1 answer

Angular service registered with container without specifying "providedIn"

The angular docs recommend registering a service with the container 1) in the root scope, generally, or 2) in the scope of a particular module. So in the general case, like this: @Injectable({ providedIn: "root" }) However I see lots of code like…
lonix
  • 14,255
  • 23
  • 85
  • 176
2
votes
2 answers

Circular reference between app and infra layers .Net Core

I'm developing an application that has three layers: Application, infrastructure and domain. The application layer is a WebApi, and the rest are Class Library. The infrastructure layer depends on the domain and application layer. The application…
2
votes
3 answers

dependency inversion in top class (main)

i want to create an app in which i have these two classes, MainApp and Model (in reality more, but this is the base and the core of the problem). MainApp is also the starting class. I want to apply dependency inversion so mainApp doesn't have to be…
hcb
  • 8,147
  • 1
  • 18
  • 17
2
votes
1 answer

Handle IoC configuration with shared dependencies between projects

I've a root project (root), some modules (A, B), and these modules have some external dependencies (Z). I'm using an IoC container. I'm using C# here, but is a generic pattern question. Let say that my container is services, and I can initialize IoC…
2
votes
1 answer

Should I use Singleton registrations in Simple Injector?

In my registry, I'm registering a lot of things as Singleton. I'm doing this because they're all thread safe and have no state. Therefore, one instance in memory is fine. I'm also using AsyncScoped lifestyles for types that need context/state, but…
Steve Dunn
  • 21,044
  • 11
  • 62
  • 87
2
votes
3 answers

.NET Core DI, register a default implementation for a package

How can one register a default implementation using the IoC container for .NET Core and also provide a way to override the existing implementation ? For example, I might want to create a package which provide a default implementation for some…
user9124444