DI, dependency-injection, is a design pattern where dependencies (instances of objects, properties) of a component are set through the constructor(s), methods or fields (properties)

learn more… | top users | synonyms

0
votes
1answer
57 views

What is a relation between Dependency Injection, single instance, and singletons?

I read So Singletons are bad, then what? which was a great explanation of dependency injection as the solution for inversion of control. The asker assumed singleton and single instance were synonyms, ...
0
votes
4answers
412 views

Is it bad to use DI to inject constructor parameters at runtime?

These are two classes, the first one I inject an instance of type IEngine while the second one I inject owner's name, tickets and engine. Version 1: public class Car { public Car(IEngine ...
0
votes
1answer
40 views

Simple Injector in Onion Layer Architecture

I'm trying to find a good resource, advice, etc in a project I've taken on for myself at work. Background When I started here we had a application that was part MVC part Webform (separate projects ...
1
vote
1answer
56 views

How to manage coupling in model classes

I'm doing a class diagram for a game project, but I'm stuck on a coupling problem. Context The projet is a turn-based game. Two users are playing. They've got units on a map. They play until 1 ...
0
votes
0answers
41 views

How to clean composition root from anything other than object construction?

I'm doing poor man's DI (manual injection) in my application. My (pseudo-) composition root looks something like this: var connectionSettings = new Settings(SqlParameters) var dataLoader = new ...
0
votes
1answer
119 views

IOC Between Presentation and Infrastructure Layer

Question: I would like to set forth dependency mapping from a *.config file from a project that has no reference to the project that contains the concrete class. Scenario: I'll be using terms from ...
1
vote
1answer
39 views

Issues about static injection in Spring?

I use spring-boot with spring xml in my project. I wrapper the DAOs in a DataAccessService class to serve as a DB service layer, both the service and the DAOs are injected in spring xml and used by ...
3
votes
2answers
182 views

IoC as service locator

I have been wondering for quite some time on some issues while using dependency injection: In a layered application, I normally inject repositories into the application service using constructor ...
1
vote
3answers
187 views

Why does dependency injection encourage collaboration to be exposed via constructors?

The general approach to DI that I see in answers like So Singletons are bad, then what? encourages business objects that collaborate with other objects to (a) not directly create those instances and ...
1
vote
1answer
159 views

C# Dependency Injection Placement

This is my first time using Unity so bear with me for a moment. I have a sample Visual Studio 2012 project with 4 projects (but only two of these projects will be used with Unity). This is the ...
0
votes
0answers
71 views

Am I following a good design thought process? Is the Abp framework overkill?

As I finish one project and start another, I have a small time window to come up with an architecture for the new. I am coming from the following design: Web applicationReceives domain models & ...
0
votes
0answers
24 views

Data serialization architecture, injection on construction vs. on function call

I am creating a data serialization/deserialization mechanism for essentially a persistent storage object. Due to the variety of systems this mechanism could run on, there needs to be a a variable ...
1
vote
2answers
223 views

when using dependency injection, should I always pass an interface

When using depending injection, you generally pass everything around as an interface (perhaps with the exception of primitives and strings). That allows you to easily chance the behavior, without ...
14
votes
3answers
681 views

I get dependency injection, but can someone help me understand the need for an IoC container?

I apologize if this seems like yet another repeat of the question, but every time I find an article regarding the topic, it mostly just talks about what DI is. So, I get DI, but I'm trying to ...
1
vote
2answers
140 views

Why do IoC containers provide public Resolve method(s)?

In my opinion it just inverses the inversion and could make new users (including myself) make incorrect assumptions about using IoC containers. It can be used for the Service Locator (anti-)pattern ...
1
vote
1answer
154 views

Should the Presenter depend on the View or the vice versa?

So far, I have used the MVP architecture pattern a few times. Every now and then, I wonder whether my Presenter should depend on my View or vice versa, that is the View depends on my Presenter. NOTE ...
4
votes
3answers
236 views

Reducing dependency cycles and reducing coupling

I'm trying to learn how to produce quality object-oriented code and have been studying concepts like SOLID. I'm currently working on an entity-component-process system for a small game engine. ...
0
votes
1answer
58 views

Value Object: static factory or assisted injection?

First let assume that everybody agree that there is nothing wrong with injecting some value object into injectable object such as service. Indeed, a service can get another service injected, but could ...
2
votes
2answers
190 views

Dependency Injection: where to store dependencies used by only one method?

I am developing a project integrated with Dependency Injection (just for reference, I'm using Unity). The problem is that I have some Manager classes with several methods and in many cases I have ...
4
votes
5answers
437 views

Questioning one of the arguments for dependency injection: Why is creating an object graph hard?

Dependency injection frameworks like Google Guice give the following motivation for their usage (source): To construct an object, you first build its dependencies. But to build each dependency, ...
1
vote
1answer
88 views

Ninject/DI: How to correctly pass initialisation data to injected type at runtime

I have the following two classes: public class StoreService : IStoreService { private IEmailService _emailService; public StoreService(IEmailService emailService) { _emailService ...
1
vote
2answers
94 views

How best to construct our test subjects in unit tests?

Some of our business logic classes require quite a few dependencies (in our case 7-10). As such when we come to unit test these the creation become quite complex. In most tests these dependencies are ...
1
vote
2answers
239 views

How to handle “circular dependency” in dependency injection

The title says "Circular Dependency", but it is not the correct wording, because to me the design seems solid. However, consider the following scenario, where the blue parts are given from external ...
5
votes
1answer
357 views

Decoupling when constructors have non-contractual parameters

By non-contractual parameters, I mean parameters that are not interfaces or service dependencies, something like class Person(string name). I am writing a webpage scraping application, and so far ...
0
votes
1answer
181 views

When to use packages or Repositories in Laravel?

I'm a Laravel (PHP) developer, and new with DI, Packages (workbench) and Repositories (Pattern). I want to know about the best concept/methodology for a more flexible design; ie. the project can grow ...
2
votes
1answer
53 views

Are the required parameters of a function called dependencies?

I'm studying dependency injection and I want to know if required function parameters can be considered dependencies. I'd just like to make sure before I go around referring to them dependencies and ...
1
vote
2answers
98 views

How should one implement the dependency-injection for a geocoding client that aggregates different coordinate provider implementations?

I am new to DI and I would like to know how DI might be used to help resolve this problem. If I have an ILatLongLocation which implements a Latitude and Longitude, then given two of these I can ...
0
votes
0answers
132 views

Save database changes in service layer or controller mvc .net

I have recently been using a service layer to abstract away alot of the business logic of my application. However I've come into an issue where I'm not sure what is best practice on doing the actual ...
0
votes
1answer
142 views

How can I use guice to replace code dependent on service locator implementation?

Consider I have a service called FileSystem, and that this FileSystem is used by various classes throughout the application. Typically, the service is acquired via some static class method ...
3
votes
1answer
169 views

Showing a View from another View in MVP

This question is regarding MVP triads. Lets say I have two triads and first one has View1, Mode1 and Presenter1. Second triad has View2, Model2 and Presenter2. Now what I trying to do is, I just want ...
5
votes
4answers
440 views

What complexity do DI frameworks add? [closed]

The currently most upvoted answer to a very recent question states that DI containers are an "enterprise software" pattern, used when the object graph is very large and complex. I suspect that 95% ...
11
votes
3answers
398 views

Do dependency injection frameworks pose a dependency risk?

I have been refactoring an existing system to use dependency injection, and that work has been going smoothly. After a while I noticed that a large number of in-house libraries became dependent upon ...
30
votes
3answers
3k views

How does dependecy injection increase coupling?

On the Wikipedia page on dependency injection, the disadvantages section tells us this: Dependency injection increases coupling by requiring the user of a subsystem to provide for the needs of ...
1
vote
1answer
103 views

How to properly handle conditional dependencies in a factory?

Let's say you have a string $action run-time, that specifies which type of $object needs to be created: $dbobject, $memcacheobject, $fileobject, $xmlobject, etc. Assume also, that creation of an ...
2
votes
1answer
169 views

How to handle passing multiple dependencies in a module hierarchy

So I have my application consisting of a number of modules in a module hierarchy. Furthermore let's also assume each module is a class and we have a tree of classes where the classes at the top are ...
0
votes
1answer
204 views

Applying DDD to a simple app with a configuration twist

I’m using the light-weight PHP Fat-Free Framework as a base to form a simple MVC based app with DDD philosophy for the Model layer. I’m aware that DDD is most suitable or enterprise solutions and that ...
3
votes
3answers
137 views

Using 2 Constructors: one that injects dependencies and one that instantiates them

I started using TDD for the first time on a project I started recently. I have a few objects with dependencies and structures that look something like this: public class MyClass { private ...
4
votes
2answers
85 views

How to extend Constructor Injection?

Suppose I have MyClass with a very simple dependency. It uses constructor injection. public class MyClass : IMyClass { private IA A; public MyClass(IA a) { A = a; } } This ...
1
vote
2answers
373 views

Where should I put bindings for dependency injection?

I'm new to dependency injection and though I've really liked it so far, I'm not sure where bindings should go. I'm using Guice in Java, so some of what I say might be specific to just Guice. As I see ...
5
votes
1answer
455 views

To Repository Or Not To Repository

When I first learnt about Domain Driven Design, I was also introduced to the repository and unit of work patterns that once seemed to be top notch for the cool kids that threw SQL queries like ...
1
vote
2answers
96 views

Dependency injection for request variables in a web application

I'm working a PHP 5.5/MySQL web application. If a class depends partly on some global GET and POST variables for its members, should I just refer to them directly from within the class, or should I ...
0
votes
0answers
590 views

Spring bean injection into a hibernate validator constraint

I have a controller method like listed below whose argument is annotated with @Valid to validate PasswordChange object using a Hibernate validator @Constraint. Both PasswordChange and a sample ...
0
votes
1answer
94 views

How to design a domain entity that uses a dependency to manage a state field?

I'm new to DDD and IOC/DI and I'm having some trouble figuring out how to design an entity that needs to use a state pattern to manage its status. As the transitions are somewhat complicated, I'm ...
0
votes
1answer
229 views

Pooling (Singleton) Objects Against Connection Pools

Given the following scenario A canned enterprise application that maintains its own connection pool A homegrown client application to the enterprise app. This app is built using Spring framework, ...
1
vote
1answer
415 views

Organising data access for dependency injection

In our company we have a relatively long history of database backed applications, but have only just begun experimenting with dependency injection. I am looking for advice about how to convert our ...
1
vote
2answers
161 views

Dealing with an often occuring dependency that is not related to the class

I'm using view classes for my templating. These view classes often require the Routing class to get URI's from other pages. You could actually say that the Routing should be available to every view ...
1
vote
0answers
134 views

State Pattern Code for embedded device - Dependency Injection of Device Objects in Context and State Classes

I'm wrestling with some code and I think I've finally gotten some state pattern code working with my events. I've got a simplified system that will work like this: This is my first go with State ...
6
votes
3answers
231 views

Dependency Injection vs Mixing Levels of Abstraction

I've been reading Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin. One point he makes: G34 Functions should descend only one level of abstraction However, I'm ...
1
vote
2answers
201 views

Initialization of objects in a system using dependency injection

This is a follow up question to the following post: Injecting dependencies (DI) in c++ applications In a system that uses DI, someone, somewhere should be responsible to create the various objects ...
2
votes
2answers
408 views

Injecting dependencies (DI) in c++ applications

I am playing with dependency injection, but i am not sure I am doing it right. Especially, I am not sure what should be the correct way to build classes with injected dependencies. Say I have a class ...