Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

-2
votes
0answers
23 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 ...
0
votes
0answers
27 views

Using Autofac (or any IoC) to customize a core product?

We are trying to implement a plugin system where a Customer Project can override small bits of a Core Project in order to make the app custom to a specific customers requirements.. We are working with ...
0
votes
0answers
69 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 ...
1
vote
2answers
79 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 ...
3
votes
2answers
173 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 ...
0
votes
1answer
90 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 ...
-1
votes
1answer
78 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 ...
4
votes
5answers
424 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 ...
-2
votes
1answer
143 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, ...
1
vote
0answers
210 views

IoC - Should I use child containers to create scoped dependencies?

I have a number of command handlers defined for doing work against databases on various servers in our network. I am wondering if I should design each command to pass the following information in the ...
3
votes
2answers
87 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 ...
1
vote
0answers
64 views

What is the appropriate pattern for an extendable application framework?

I have created a basic, domain-specific application framework for a web-based GUI. The framework provides Undo/Redo of 'Operations', persistence, and other more domain-specific functionality. I am now ...
12
votes
3answers
3k 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 ...
3
votes
3answers
333 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 ...
17
votes
2answers
1k 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 ...
2
votes
0answers
656 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 ...
2
votes
1answer
64 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 ...
1
vote
2answers
92 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....
4
votes
4answers
781 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 ...
0
votes
2answers
2k 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 ...
3
votes
1answer
217 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 ...
1
vote
1answer
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 ...
1
vote
4answers
854 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 { ...
0
votes
2answers
513 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) ...
6
votes
2answers
8k 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 ...
5
votes
3answers
883 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 ...
6
votes
3answers
834 views

How do I support per-method-call instantiation without referencing the IoC container outside the composition root?

I read with interest this article which states: A DI Container should only be referenced from the Composition Root. All other modules should have no reference to the container. This means that ...
6
votes
3answers
142 views

Passing database connection to the library

I'm writing java library(jar file) to log Web service request and responses in a Database for in-house application. This library will have two methods registerReuqest and registerResponse. I'm ...
1
vote
0answers
121 views

Inversion of control in controller by a mediator

A user has to perform a somewhat complex task on my website (submitting a rating). For the sake of example, let's consider it's a rating for a movie, done through a controller. There are several ...
11
votes
5answers
3k views

Using Func instead of interfaces for IoC

Context: I am using C# I designed a class, and in order to isolate it, and make unit testing easier, I am passing in all its dependencies; it does no object instantiation internally. However, instead ...
7
votes
3answers
463 views

Is it good practice to register development mocks using conditional compilation?

I'm developing an application that connects to a database, and I'm using DI/IOC. When running the entire application while developing, I naturally want to avoid hitting the DB. Currently, I have ...
4
votes
1answer
208 views

Does an IoC Container affect the design of an application using Dependency Injection?

Is it safe to say that a Container is the "program" or mechanism that manages IoC via DI, but it doesn't really change your initial design of DI to accomplish loose coupling? In other words, if I ...
1
vote
0answers
324 views

Opening new Window from ViewModel using Castle Windsor

I've been following the quick tutorial on using Castle Windsor in MVVM WPF: TUTORIAL I've set everything up (as for the basics) but I came to the point of creating a new Window after a button click. ...
1
vote
1answer
400 views

Implementing IoC the right way

I started working in a project around 3 months ago and since I joined I saw so many mistakes in the whole design - the architecture is completely dysfunctional and badly implemented and a lot of used ...
2
votes
2answers
392 views

IoC Framework vs. DI Layer

Say we have a class structure like the following: // implementation.ts export class A implements IA { constructor(private b: IB) {} } export class B implements IB { constructor(private c: IC) ...
0
votes
1answer
214 views

How to use dependency injection for applications that are configurable at startup?

I'm writing software that needs to be fairly configurable in nature. At this point what that means is that it first reads in a users configuration file and then builds the objects it needs based on ...
23
votes
7answers
14k views

What is the “right” way to implement DI in .NET?

I'm looking to implement dependency injection in a relatively large application but have no experience in it. I studied the concept and a few implementations of IoC and dependency injectors available, ...
3
votes
4answers
1k views

Class Library - How to communicate between objects that are not aware of each other?

I am trying to improve my programming skills and knowledge and I have been doing some reading about various design patterns and youtubing videos etc. One subject I thought was interesting was about ...
3
votes
1answer
695 views

IoC, Unity: Creating a component with additional concrete parameters

I am struggling with the following issue. Let's say I have a component that performs operations on guests and rooms, and uses a number of abstract interfaces, along the lines of: class HotelManager { ...
4
votes
3answers
434 views

Missing dependencies at compile-time with IOC

Thanks to my new job, I recently discovered the inversion of control design principle (with windsor castle in C#). I really enjoy using it but something's bothering me. For me the good part about ...
8
votes
2answers
2k views

Service-locator anti-pattern alternative

I'm using Unity as IoC with C#, but I guess the question really isn't really limited to Unity and C#, but IoC in general. I try to follow the SOLID-principle, which means that I got very few ...
4
votes
2answers
2k views

Dependency injection use in “Clean Code” by Robert Martin

In Robert Martin's Clean Code, I encountered the following method on p. 195: private void parseSchemaElement(String element) throws ArgsException { char elementId = element.charAt(0); String ...
6
votes
4answers
1k views

How does a Dependency Injection/IOC Container know which implementation to use?

When you use an IoC container, like so: var svc = IoC.Resolve<IShippingService>(); How does the IoC Container choose which implementation of IShippingService to instantiate? Further, if I am ...
10
votes
1answer
3k views

How is Inversion of Control related to Dependency Inversion

In many articles all over the web the terms Inversion of Control and Dependency Inversion Principle seem to be mixed up and used as synonyms (further confusion is enforced by the tools that are called ...
1
vote
1answer
373 views

How far do I separate Model code from Controller code when writing MVC?

I have some code where Controller depends on the Model, and in my case Model acts like a Database Access Object. use FQDN\Model; class Controller { /** @var FQDN\Model */ private $model; ...
0
votes
2answers
92 views

What is the name for user-defined methods / functions that get called implicitly? [closed]

I want to mark such methods in my application code with a comment that highlights that these methods are expected to get called by the framework / compiler the application is written for, even if the ...
3
votes
2answers
680 views

Best practice in helper/util methods: IoC container or static methods?

So I'm developing an application which is using an IoC container. Now I need some helper methods for array manipulation like set, get, etc. I see two possible ways to go: Using a class with static ...
0
votes
2answers
328 views

IoC container with lifetime attribute [closed]

Which ioc frameworks for .net can use concrete type attribute to choose it's lifetime? Here is a simple example public interface IService {} [Singleton] public class ServiceImplA : IService {} [...
38
votes
4answers
10k views

Why do we need frameworks for dependency injection? [closed]

I've been reading up more on the Inversion of Control principle and Dependency Injection as an implementation of it and am pretty sure I understand it. It seems to be basically saying 'don't declare ...
0
votes
1answer
131 views

Does this structure satisfy the terms of the Inversion of Control principle?

I'm trying, as a test, to create Dependency Injection from scratch in JavaScript. Consider the following code structure, which outputs an Alert: Does it satisfy the terms of the Dependency Inversion ...