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.

Filter by
Sorted by
Tagged with
-1 votes
7 answers
563 views

If you use Inversion of Control, what alternatives to obfuscated function calls exist?

Consider a class that follows the obfuscated function call anti-pattern. I've also seen these called "stupid classes". The definition of such a class is that it only has one public method ...
J. Mini's user avatar
  • 997
0 votes
0 answers
84 views

How to use an external event queue with inversion of control (IoC)

I'm working on an AspNetCore application, with a requirement to raise and handle certain events asynchronously using an external event queue. I'll use AWS services as examples here because that's what ...
brads3290's user avatar
  • 135
1 vote
2 answers
194 views

Why do we separate interface when implementing interface injection variant of DI?

With interface injection (wikpedia) we have a method to set the dependency on the client as part of an interfase. public interface ServiceSetter { public void setService(Service service); } Why ...
Nishant Chauhan's user avatar
1 vote
2 answers
2k views

Dependency Injection vs Static Dependencies

I am building a wrapper for a library that requires little complex logic. The whole project is 8 builder classes, 4 classes for doing some pre-processing, and a couple visitor classes. Essentially I ...
EspressoCoder's user avatar
2 votes
2 answers
202 views

Abstracting calls to common library methods in C#

I‘m working on making a legacy code base more testable and made good progress with (constructor)-injecting dependencies to classes. I noticed something in all classes that access the file system: they ...
Der_Reparator's user avatar
0 votes
2 answers
200 views

Services should depend on Data or Factories?

I have app which uses IOC container. I have services registered in container, and I can consume either data factory, or particular data object. Which approach is preffereable? Consuming factory object:...
Shadow's user avatar
  • 363
0 votes
2 answers
363 views

Is it safe to use the same IoC container for your own and third-party services?

I am developing an application with ASP.NET Core with the ability to dynamically add new libraries that implement the necessary functions. They can be included at the start. I have already written ...
Ramir Gimaltdinov's user avatar
0 votes
1 answer
273 views

Inject configuration files into the injector is it an antipattern?

I'm trying to design a system that inject configuration of each component into each class. project structure: |features --|component-a component-a.service.js component-a.config....
Slim's user avatar
  • 109
0 votes
6 answers
698 views

If it is a bad practice to use an interface if only one class will implement it, what is the purpose of IoC container?

Okay, first of all I understand the concept of IoC container! It's used to implement automatic dependency injection so you won't have to manually inject dependencies to class. It can automatically ...
Jhe's user avatar
  • 17
-2 votes
1 answer
278 views

Is there a proper way of implementing runtime control of dependencies using DI? Is factory pattern okay? [closed]

I'm currently brushing up and learning about a bunch of techniques to hopefully begin implementing in my own workflow; one of which is IoC (and DI in particular). I'm hoping someone could clear up my ...
Buretto's user avatar
  • 117
-3 votes
2 answers
450 views

Is inversion of control the opposite of "tell, don't ask" principle?

First, let me explain what I mean by inversion of control and tell, don't ask in this context. I have 4 classes MailController, UserData, Subscription and MailService. MailController is a consumer of ...
I Want Answers's user avatar
4 votes
1 answer
789 views

Dependency Injection: What are advantages of using a framework? [duplicate]

Introduction and Question I understand what the advantages of dependency injection, e.g. constructor injection or setter injection and that it is one way of doing inversion of control. I also ...
Make42's user avatar
  • 307
0 votes
2 answers
159 views

Inversion of control

I have been reading about inversion of control and dependency injection and I was wondering the following. Is there a good way to tell when it is okay to initialise an object inside a method body of a ...
Andreas Andreou's user avatar
3 votes
3 answers
877 views

How to decouple chain hierarchy project dependency by dependency injection? (C# .Net Standard)

I'm working on decoupling a Xamarin (.NetStandard) solution. It was using DryIOC container but I didn't see the IOC structure from the dependency, as the projects are still tightly coupled. Three main ...
Shaw's user avatar
  • 133
1 vote
1 answer
128 views

Inversion of control - no "new" in a low level constructor?

When using IoC in a code base, should one always stick strictly to the pattern without exception? That means there should be no "new" in any constructor, when the newed object has ...
TomatenSalat's user avatar
-3 votes
2 answers
129 views

Dependency access control in DI

As I'm just getting into ASP.NET Core, I'm also continuing to slowly learn about Dependency Injection and still trying to identify some value in it for our practical purposes. The point I've reached ...
xr280xr's user avatar
  • 189
1 vote
2 answers
1k views

Default value for constructor dependency injection

I have class A that depends on interfaces B & C. I use constructor injection to inject them into A: class A { let b: B let c: C init(b: B, c: C) { self.b = b self....
RodYt's user avatar
  • 69
0 votes
1 answer
148 views

Mixing IoC container use with "poor mans" DI

I'm finding the use of IoC containers to be quite the shift in my application design, and its for the better. I'm using a framework called injector that aims to mimic (albeit not entirely) the Guice ...
pstatix's user avatar
  • 1,017
1 vote
1 answer
101 views

How far we have to consider the plug-ability while designing an email service using external library

I was designing an email service in .net standard 2.0 using mailkit library. I proposed the following design This design was not accepted stating the following reasons: This design have to many ...
Anjo's user avatar
  • 215
0 votes
0 answers
97 views

Instantiating adapters in onion architecture

GitHub and NuGet Do you use connection strings to instantiate your adapter services or just always configure it through IoC? I think that connection strings could provide a way more flexibility, ...
Dmitry Nogin's user avatar
1 vote
1 answer
452 views

What's the difference between Strategy Pattern and IoC

In both the Strategy Pattern and in Inversion of Control you can exchange parts of an object that allows scalability and easy-to-exchange parts. I am referring to this and this Both use an interface ...
user avatar
1 vote
2 answers
847 views

How to configure and setup an IOC Container for a library?

When using Dependency Injection across internal classes (implementation details) in a library which is to be consumed by multiple applications, is there a good way to configure the IOC container? ...
brent's user avatar
  • 121
1 vote
1 answer
592 views

IoC/DI + "normal" constructor arguments mvvm

I am using unity in C# to achieve dependency injection and inversion of control. What if I have a class, let's say a viewmodel, that depends on several services like a repository, a validator and a ...
DFENS's user avatar
  • 375
2 votes
2 answers
1k views

Does SOLID Require an IoC Container (Automatic Factory)?

The fifth concept in the SOLID principle is the dependency inversion principle. It is heavily related to dependency injection, and Inversion of control, and when any of these concepts are mentioned, ...
Christian Findlay's user avatar
1 vote
1 answer
569 views

How to define Composition Roots for libraries (Javascript/inversify)

I'm building a console app (A), which depends on library B. Library B further depends on library C. I am building all 3 entities. Most of the development completed so far has been done using a ...
Plastikfan's user avatar
0 votes
2 answers
1k views

Passing runtime-read configuration when working with an IoC container

I've recently "discovered" the IoC realm, and decided to refactor a project I'm working on to use such a container. To be specific - I'm using autofac in C#, in a .NET Core console application. The ...
Timor Gruber's user avatar
0 votes
0 answers
296 views

How to setup up a background thread/task which triggers UI updates?

Background I'm designing a round-based game where one of the core design goals is to have a highly exchangable UI. For this, I've defined an interface which allows implementers to only focus on ...
Tim Meyer's user avatar
  • 833
2 votes
1 answer
54 views

Where does the responsibility for clearing higher-level caches lie in a pyrimidal calculation system with caching at multiple levels?

I'm working on system that analyses non-trivial amounts of data. The analysis is pyramidal, in that various combine to make intermediate values, which in turn combine with each other and more inputs ...
Oblivious Sage's user avatar
0 votes
0 answers
155 views

Is using IoC with data classes a good practice

I usually use IoC frameworks to inject dependencies that are services. Is it ok to mark classes that are data objects as IoC components? To be more clear I will give an example. I have an abstract ...
Mikołaj Mularczyk's user avatar
1 vote
2 answers
142 views

In some IOC contexts, could constructor of polymorphic immutable object be required in its interface?

Generally, constructors in an interface are considered as being an anti-pattern. Some languages even don't allow that. Then I don't understand how we're supposed to deal with polymorphic immutable ...
ClemC's user avatar
  • 391
4 votes
2 answers
1k views

Passing DI container to a factory – is this always an antipattern?

Generally I would always answer "yes" to this question, because at this point, your DI container has become a service locator, and you're losing the benefits of DI. However, I wonder if it is ...
user avatar
0 votes
1 answer
277 views

Evaluation of (a)synchronous design of ledger interface

I'm currently designing a ledger API, that should work with different implementations (e.g. based on Blockchain, traditional databases, or files). Its purpose is to add/get messages to/from a ...
mike's user avatar
  • 153
0 votes
1 answer
121 views

Is Dependency Injection A Standard in PHP and Laravel?

Or in actuality, how to tell if a certain technique has became a standard in certain language / framework? As I understood from my readings so far, PHP supports DI in PSR-11 while Laravel uses it out ...
krubix's user avatar
  • 19
6 votes
5 answers
4k views

How can you use DI without DI framework in a reasonably complex project?

edit I asked this question not because this is my opinion, but because I am trying to understand someone else's. Personally I prefer IoC via DI (in my specific case Simple Injector) but not everybody ...
Benjamin Diele's user avatar
-2 votes
1 answer
617 views

Why EJB service Injection requires the specific subclass to be created?

Most Java EE guidelines suggest that we should define Abstract EJB services (APIs) and then define concrete implementations in order to conform with OO design principles. But at the injection point, ...
Theodore's user avatar
4 votes
2 answers
126 views

Simple examples of properly designed Asp.Net applications illustrating different service layers?

I've been programming professionally for years now at several different companies and I consider myself to be a fairly competent programmer. However, of everywhere I've worked there are usually dozens ...
JD Davis's user avatar
  • 1,367
21 votes
3 answers
11k views

Is Poor Man's Dependency Injection a good way to introduce testability to a legacy application?

In the past year, I created a new system using Dependency Injection and an IOC container. This taught me a lot about DI! However, even after learning the concepts and proper patterns, I consider it ...
Airn5475's user avatar
  • 335
2 votes
3 answers
509 views

IOC container & accessing Implementation from the container

Background As mentioned in this article, Inversion of Control can be achieved through various mechanisms such as: Strategy design pattern, Service Locator pattern(SLP), Factory pattern, and ...
user1787812's user avatar
18 votes
2 answers
2k views

Is there evidence that the use of dependency injection improves outcomes in software engineering?

Notwithstanding its popularity, is there any empirical evidence that shows that Dependency Injection (and/or using a DI container) helps with, say, reducing bug counts, improving maintainability, or ...
NMrt's user avatar
  • 479
2 votes
0 answers
858 views

Dependency Injection: Creating object factories vs. using inversion of control containers [closed]

When requiring to use dependency injection, I always use IoC containers such as Ninject, Unity, or the built-in one in ASP.Net Core MVC. However, I've just come across the idea of "why not creating an ...
Arnold Zahrneinder's user avatar
2 votes
1 answer
106 views

Responsibility for adding and ordering menu items in a modular application

Following Ordering menu items fed from multiple modules the question was raised to me, who is responsible for ordering and alignment of menu items in a modular application. The previous link suggests ...
Creepin's user avatar
  • 219
1 vote
2 answers
152 views

IoC configurations - one file/assembly in solution or one file per executing assembly?

We're wondering what the best practise for registering types in a IoC-Container is. What would be arguments for and against the following principles: Principle 1: Only one Assembly my.project....
xeraphim's user avatar
  • 339
6 votes
4 answers
2k views

How to pass data between objects when an IoC container is being used?

I'm working with a project that our architect has decided to use dependency injection for almost everything. We use an IoC container. One of the main issues that I keep coming across when using this ...
Jacob Brown's user avatar
0 votes
2 answers
4k views

Using generics for dependency resolution constraints

I have such problem: the interface with no in and out parameters. public interface IIndexer { void FillIndex(); } It should work differently for different kinds of activities( comments, likes ...
Mykhailo Kilianovskyi's user avatar
2 votes
1 answer
384 views

What is the generic implementation of design pattern IoC coupled with Factory for DAO? [closed]

I'm learning the java Spring framework. So far, I understood that Spring will make stuff transparent with its configurations so that IoC and Factory are not too complicated to implement... Now I have ...
Jason Krs's user avatar
  • 179
1 vote
1 answer
2k views

Service locator vs Dependency Injection?

I have a class which acts as a Adaptor between an HTTP request and our Application's custom domain request. So every Http request element: URI, headers, content are mapped to our customized domain ...
Siddharth Trikha's user avatar
1 vote
4 answers
1k views

Image processing - Service locator pattern & Container of dependencies

As per wiki, A dependency is an object that can be used (as a service). here is the OOP paradigm using C syntax that address 4 roles, shown below. 1) interface (handlers.h) typedef struct { ...
overexchange's user avatar
  • 2,245
0 votes
2 answers
687 views

How to create a factory method

Say I have a Business class called person: public class Student { } Say I want to create a factory method for this Student class - something like this: public Student getStudent(string studentType) ...
w0051977's user avatar
  • 7,031
13 votes
4 answers
20k views

Dependency injection for a library with internal dependencies

Background I am working on a class library in support of a web site. The library combines related APIs from several different vendors, all of which have their own particular nuances and domain ...
John Wu's user avatar
  • 26.1k
4 votes
3 answers
2k views

DependencyInjection - Constructor over-injection smell vs service locator - where is the proper approach?

I am trying to improve my MVC projects and I read a few articles about DI, IoC containers, Constructor Injection and Service locators. I wanted to go with Ninject to help with the dependencies, but ...
Bartosz's user avatar
  • 597